php - Laravel - Using bundle to retrieve data from db -
first of all, i'm new laravel , mvc environment. project, i'm using mysql database , charisma bundle. i'm having difficulties when trying retrieve data db. wonder if guide me through these problems.
- if i'm using bundle, put models, controllers , routes? in
/application
folder, or in bundle's folder itself? - when use
/application
folder, , when use charisma folder? (obviously, i'm using front-end ui) - i have record in database table (named
user_links
) test data retrieval in charisma view. how go that?
i'm using crud tutorial in laravel guide, it's little confusing when comes using bundle.
ok, let me try way. i'm going retrieval here. hope can point out mistake , guide me 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 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 $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 errors, if need more please let me know. in advance.
you should use application folder front end ui
because charisma admin bundle , it's been designed applications, have end support setup , maintain various system configurations, custom cms
.
in laravel-3
application
folder default place keep controllers, models , views in corresponding folders , use application/routes.php
routing controllers.
but, if want use different bundle charisma
should keep bundle in root of bundle directory , add bundle name array in bundles.php
file. example, i've used charisma
bundle admin panel in 1 of projects , name of folder admin placed charisma
's files (i renamed charisma admin)
return array( 'admin' => array('handles' => 'hit_admin'), <-- added admin bundle // more bundles.......... );
and directory structure domain_root/bundles/admin
, admin charisma
(renamed) , have use bundles routes.php
controllers of bundle. example, in domain_root/bundles/admin
had routes.php
file , i've registered routes admin bundle in file , admin bundle had it's own controllers, views, models , public folders. so, basically, had use folders. admin controllers in domain_root/bundles/admin/controllers
folder , same models , views too. every bundle has it's own public folder keep it's own assets.
and in admin/routes.php
route this
route::any('(:bundle)', array('as' => 'admin_home', 'uses' => 'admin::home@index'));
also every controller in admin bundle can extend it's own base controller, example, used,
class admin_home_controller extends admin_base_controller { // ... }
and there base.php
file in admin/controllers
folder admin base controller , this
class admin_base_controller extends controller { public function __construct() { parent::__construct(); // add assets admin asset::add('jquery', 'js/jquery-1.7.2.min.js'); } public function __call($method, $parameters) { return response::error('404'); } }
for more information can take @ this tutorial , read documentation too.
Comments
Post a Comment