Joomla problem with MVC component - model-view-controller

I have problem with Joomla layouts in my component..There must be something bad with file/class name convention..
I was trying to ask on Joomla developer forum, but noone answered..
So I am getting this error.. 500 - View not found [name, type, prefix]: PostToBank,,postToBankView
The view is in views/postTobank/view.php and name is postToBankViewPostToBank
In my controllers/controller.php file I have class named PaymentController which contains this part of code.
$view = $this->getView('PostToBank','','postToBankView');
$this->getModel("Payment")->savePaymentData($data);
foreach ($data as $key => $value) {
$view->assignRef($key, $value);
}
$view->setLayout('postTobank');
$view->display();
my view.php file looks like this
class postToBankViewPostToBank extends JView{
function display($tpl=null){
//display set template
parent::display($tpl);
}
}
on attached image is full folder structure of my component..
Please whats wrong with this?Thanks

Joomla uses a naming conventions and you are not following them. Refer to http://docs.joomla.org/File_Structure_and_Naming_Conventions
Also, your views should be view.html.php and then you do not need to call setView.
FYI: this is where the error is coming from. Refer to this: http://docs.joomla.org/API16:JController/getView, even though it is 1.6 doc it is same in 1.5
Look though this tutorial and adopt regular conventions: http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1

Related

Laravel Trying to get property of non-object but not sure why

I want to grab some data from a database and display on a layout page, I've basically started building a small CMS to get into Laravel and all has gone fine so far but now i'm at a wall, and can't find a solution.
I have a layout blade file like so: http://paste.laravel.com/1fB1 nothing majot but you will see i have used $page->meta_title etc in there and in my controller i have:
public function home()
{
$pages = Pages::all();
return View::make('frontend/home')->with('pages',$pages);
}
Which I have a pages model doing nothing else really like so:
class Pages extends Eloquent {
protected $table = 'pages';
}
So why is it trying to get property of non-object and I don't really want to use a foreach because this is going to be the frontend of my 'test' website so a foreach wouldn't suite.
You'll need to access these items as a multi-dimensional array if you don't want to loop through them.
$pages[0]['field_name_here']
or
$pages[1]['field_name_here']
Its a bit of a tough one to answer without knowing how you want your CMS to work.
For example, you could have a route as {pagename} in your routes.php file, then have a page controller where you would get the requested route from the variable passed in. This would then load the page you wanted using the variable
public function page( $pagename ) {
$page = Page::where('page_title', '=', $pagename)->first();
View::make('frontend/page', array( 'page' => $page ));
}
Using a route like that, and the controller, in your view you could use {{ $page->content }} to get the content of the requested page from the database and display it.
Hope this helps.
Edit: Example Route:
Route::get('{pagename}', 'PageController#page');

joomla override model for mod_banners

I'm using Joomla 3.1 and I'm using template hacks to override mod_banners -
/mytemplate/html/mod_banners/default.php
Which is working fine.
However, the banners module calls the file:
/components/com_banners/models/banners.php
Which I can't seem to override. I've tried moving the file (and folders) into my /mytemplate/html folder, but that doesn't work.
I've also tried putting the following code into my banners default.php file:
JModelLegacy::addIncludePath(JPATH_ROOT.'/templates/home/com_banners/models/', 'BannersModel');
$model = JModelLegacy::getInstance('Banners', 'BannersModel', array('ignore_request' => true));
$banners = $model->getItems();
But that doesn't work either. Is there any way I can override the query in /com_banners/models/banners.php without changing the core files?
All I'm trying to do is to pull in the descriptions for each banner, without changing the core.
Thanks in advance!
The only way to override a model in Joomla is to make your own version of the original, and load (register) it through a system plugin, before the model is accessed for the first time. For your use case, that is way too complicated.
Even if it is not good practice, since it breaks up the MVC structure, I'd fetch the data from within the template.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id, name, description')
->from('#__banners');
$db->setQuery($query);
$banners = $db->loadObjectList();
Now you can access all banner descriptions, fx. in a loop:
foreach ($banners as $banner) {
echo $banner->id, ': ', $banner->description;
}

dont find the view in joomla

Hi everyone I am using joomla 2.5 for a website
I create a component to insert products in the data base in the back-end, and I want to show this product in front-end
I have this link in the view to show a products with type=1;
<div class="col2">Productos</div>
In the front-end of the component controller.php I have this
class HardwareController extends JController
function integrados(){
$model = &$this->getModel(JRequest::getCmd('view'));
$view = &$this->getView(JRequest::getCmd('view'), 'html');
$view->setModel($model, true);
$view->hardwareIntegrado();
}
in my model I have
class HardwareModelHardwares extends JModelList
function getIntegrados(){
$db=& JFactory::getDBO();
$query= "SELECT *
FROM ".$db->nameQuote('#__hardware')."
WHERE ".$db->nameQuote('tipo')."=".$db->quote("1").";";
$db->setQuery( $query);
$restaurantes=$db->loadObjectList();
JRequest::setVar('hard', $restaurantes);
return $restaurantes;
}
and in my view.html.php I have this
public function hardwareIntegrado(){
$this->assignRef('pagination', $this->get('pagination'));
$this->assignRef('hardware', $this->get('integrados'));
$this->assignRef('list', $this->get('list'));
parent::display();
}
When I click to the link I obtain this error
500 - View not found [name, type, prefix]: hardware, html, hardwareView
any idea!
You should change your view class to hardwareViewHardware
You are getting this error-
500 - View not found [name, type, prefix]: hardware, html, hardwareView
because it's looking for hardware view.In the link- index.php/hardware/integrados it seems you are passing view=hardware . Whereas everywhere you have defined it as hardwares like in folder name and class.Either change link or class and folder.
Hope this will help.

Loading and using models in opencart

Open cart is based on CodeIgniter as I understand but in CodeIgniter to load and use the model you do something like this
$this->load->model('Model_name');
$this->Model_name->function();
In OpenCart you do something like this
$this->load->model('catalog/product');
$this->model_catalog_product->getTotalProducts()
How does this work and where does the "model_catalog_product" come from?
It seems like they have 0 developer documentation besides their forums.
OpenCart's loader class seems to be inspired by CodeIgniter, but it's not based on it. You can look into the source of OpenCart, see file system/engine/loader.php (Line 39).
public function model($model) {
$file = DIR_APPLICATION . 'model/' . $model . '.php';
$class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model);
if (file_exists($file)) {
include_once($file);
// Right here. Replaces slash by underscore.
$this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));
} else {
trigger_error('Error: Could not load model ' . $model . '!');
exit();
}
}
You can clearly see that it replaces slashes with underscores and append 'model_' before the model's name. That's why you end up with model_catalog_product.
The model_catalog_product comes from the path folder structure and file name within the model folder, so model_catalog_product is the model/catalog/product.php file, with the extension removed and the slashes changed to underscores. Also, notice that the model class name also refers to a similar structure, which is ModelCatalogProduct. As for the documentation, there was some documentation for developers, but just checked briefly and it appears that it's been removed for whatever reason. I learn't from lots of trial and error unfortunately, as have most developers using it

CodeIgniter - Dynamic URL segments

I was wondering if someone could help me out.
Im building a forum into my codeigniter application and im having a little trouble figuring out how i build the segments.
As per the CI userguide the uri is built as follows
www.application.com/CLASS/METHOD/ARGUMENTS
This is fine except i need to structure that part a bit different.
In my forum i have categories and posts, so to view a category the following url is used
www.application.com/forums
This is fine as its the class name, but i want to have the next segment dynamic, for instance if i have a category called 'mycategory' and a post by the name of 'this-is-my-first-post', then the structure SHOULD be
www.application.com/forums/mycategory/this-is-my-first-post
I cant seem to achieve that because as per the documentation the 'mycategory' needs to be a method, even if i was to do something like /forums/category/mycategory/this-is-my-first-post it still gets confusing.
If anyone has ever done something like this before, could they shed a little light on it for me please, im quite stuck on this.
Cheers,
Nothing is confusing in the document but you are a little bit confused. Let me give you some suggestions.
You create a view where you create hyperlinks to be clicked and in the hyperlink you provide this instruction
First Post
In the controller you can easily get this
$category = $this->uri->segment(3);
$post = $this->uri->segment(4);
And now you can proceed.
If you think your requirements are something else you can use a hack i have created a method for this which dynamically assign segments.
Go to system/core/uri.php and add this method
function assing_segment($n,$num)
{
$this->segments[$n] = $num;
return $this->segments[$n];
}
How to use
$this->uri->assign_segment(3,'mycategory');
$this->uri->assign_segment(4,'this-is-my-first-post');
And if you have error 'The uri you submitted has disallowed characters' then go to application/config/config.php and add - to this
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
You could make a route that forwards to a lookup function.
For example in your routes.php add a line something like;
$route['product/(:any)/(:any)'] = "forums/cat_lookup/$1/$2";
This function would then do a database lookup to find the category.
...
public function cat_lookup($cat, $post) {
$catid = $this->forum_model->get_by_name($cat);
if ($catid == FALSE) {
redirect('/home');
}
$post_id = $this->post_model->get_by_name($post);
/* whatever else you want */
// then call the function you want or load the view
$this->load->view('show_post');
}
...
This method will keep the url looking as you want and handle any problems if the category does not exist.Don't forget you can store the category/posts in your database using underscores and use the uri_title() function to make them pretty,
Set in within config/routes.php
$route['song-album/(:any)/:num'] = 'Home/song_album/$id';
fetch in function with help of uri segment.
$this->uri->segment(1);

Resources