8791 sujets

Développement web côté serveur, CMS

Bonjour à tous,

J'ai un petit probleme sous Laravel, je suis les tutos de Simpledev (tuto.com) et j'ai une erreur, lorsque j'affiche mon index.php.

Unhandled Exception

Message:

Error rendering view: [post.index]

Undefined variable: posts
Location:

/home/shipecra/public_html/application/views/post/index.php on line 1
Stack Trace:

#0 /home/shipecra/public_html/laravel/laravel.php(40): Laravel\Error::native(8, 'Undefined varia...', '/home/shipecra/...', 1)
#1 /home/shipecra/public_html/laravel/view.php(366) : eval()'d code(1): Laravel\{closure}(8, 'Undefined varia...', '/home/shipecra/...', 1, Array)
#2 /home/shipecra/public_html/laravel/view.php(366): eval()
#3 /home/shipecra/public_html/laravel/view.php(342): Laravel\View->get()
#4 /home/shipecra/public_html/laravel/view.php(570): Laravel\View->render()
#5 /home/shipecra/public_html/laravel/response.php(246): Laravel\View->__toString()
#6 /home/shipecra/public_html/laravel/laravel.php(178): Laravel\Response->render()
#7 /home/shipecra/public_html/public/index.php(34): require('/home/shipecra/...')
#8 {main}


Et voici mon controller de post.php:

<?php

class Post_Controller extends Base_Controller {

	public function action_index()
	{
		$posts = Post::all();

		return View::make('post.index')->with('posts'.$posts);
	}

}


Mon model post:

<?php

class Post extends Eloquent {

	public function user()
	{
		return $this->belongs_to('user');
	}

	public function comments()
	{
		return $this->has_many('comment');
	}
}


Et mon index.php pour l'affichages des posts :

<?php if($posts):
foreach($posts as $p):?>

<h2><?php echo $p->title;?></h2>

<p><?php echo $p->content;?></p>

<?php endforeach;endif;?>


Je suis désolé mais ça fais au moins 5 fois que regardes les video de tuto et je ne trouves pas mon erreur Smiley decu

Ps: je précise que les tables de la base de données sont bien créée Smiley sweatdrop
Modifié par cl9m9n7 (30 Sep 2012 - 14:47)
Yeah Yeah Yeah !!!

Trouver Smiley langue la petite VIRGULE à la place du point:

<?php

class Post_Controller extends Base_Controller {

	public function action_index()
	{
		$posts = Post::all();

		return View::make('post.index')->with('posts',$posts);
	}

}


entre
'posts'
et
$posts


Haaaaaaaaaaaaaaa !
Modifié par cl9m9n7 (30 Sep 2012 - 14:55)