First of all, I'm new to Laravel and MVC environment. For this project, I'm using MySQL as database and Charisma as the bundle. I'm having difficulties when trying to retrieve data from db. I wonder if someone would guide me through all these problems.
- If I'm using bundle, where do I put all the models, controllers and the routes? In
/application
folder, or in the bundle's folder itself? - When do I use
/application
folder, and when do I use Charisma folder? (obviously, I'm only using it for the front-end UI) - I have a record in my database table (named
user_links
) to test the data retrieval in Charisma View. How do I go about that?
I'm using this CRUD Tutorial in Laravel as a guide, but it's a little confusing when it comes to using bundle.
Ok, let me try do it my way. I'm going to do a Retrieval here. I hope someone can point out the mistake and guide me for a fix.:
Table name user_links
:
id: int
user_id: varchar
link_title: text
link_url: text
Model /application/models/user_links.php
(since Charisma doesn't have /models
folder, I'm gonna use the default one):
class User_Link extends Eloquent{
}
Controller bundles/charisma/controllers/user_link.php
(using Charisma controllers folder)
class Charisma_User_Link_Controller extends Base_Controller{
public $restful = true;
public function get_index(){
$user_links = User_Link();
return View::make('user_links.index')
->with('link_title', 'Link Title')
->with('link_url', 'URL');
}
}
View /bundles/charisma/views/pages/index.blade.php
:
<div >
@foreach($user_link->results as $user_links)
{{ $user_links::link_title }}
{{ $user_links::link_url }}
@endforeach
</div>
Routes /bundles/charisma/routes.php
:
Route::controller('charisma::user_link');
That's all. Of course there will be some errors, but if you need something more please let me know. Thanks in advance.