I have added this:
echo $this->getLayout()->createBlock('core/template')->setTemplate('sales/order/history.phtml')->toHtml();
to mypage.phtml, but it is giving
Fatal error: Call to a member function getSize() on a non-object in C:\xampp\htdocs\puckerimages_cvs\app\design\frontend\default\pucker\template\sales\order\history.phtml on line 41
Can anybody tell me how to call core module controller in custom pages
I dont know exactly what you were tried to do..Controller is nothing but your url segment.
If you want get controller from Url use the following code,
Mage::app()->getRequest()->getControllerName();
Mage::app()->getRequest()->getActionName();
Mage::app()->getRequest()->getRouteName();
Mage::app()->getRequest()->getModuleName();
If you want get collection of data from your Module use the following code,
Mage::getModel('groupname/classname');
or
Mage::getSingleton('groupname/classname');
Example
$collection = Mage::getModel('module/model_name')->getCollection()
->addAttributeToSort('order', 'ASC')
->addAttributeToSort('last_name', 'ASC')
->addAttributeToSort('first_name', 'ASC')
;
try this
instead of "core/template" use "sales/order_history"
<?php echo $this->getLayout()->createBlock('sales/order_history')->setTemplate('sales/order/history.phtml')->toHtml();?>
hope this help you
Related
When i try to use group_by function select query not working, and i am getting error Call to a member function result(), without group by query is working, i can't fix this issue ? can anyone please help me to resolve this issue ? here i have added my whole query
$query = $this->db->select('s.*,b.*,c.*,i.*')
->from('sales s')
->join('biller b','s.biller_id=b.biller_id','inner')
->join('customer c','s.customer_id=c.customer_id','inner')
->join('invoice i ','s.sales_id=i.sales_id','inner')
->group_by('sales_id');
$data = $query->get()->result();
return $data;
My guess is the sales_id column name on this line is ambiguous :
->group_by('sales_id');
So you could change it either using sales.sales_id or invoice.sales_id :
->group_by('s.sales_id');
In the controller, I store some data in an array.Then I want to send it in myelectionlist.blade.php
$my_election=[];
$i=0;
foreach ($election_list as $election_list)
{
$my_election[$i]=DB::table('election')
->where('id','=',$election_list->election_id)
->get();
$i++;
}
return view::make('myelectionlist')->with('election_list',$my_election);
I check with
return $my_election
It works fine. But In myelectionlist.blade.php when I write
#for($i=0;$i<sizeof($election_list);$i++)
{{$election_list[$i]->election_name}}
#endfor
It does not work.
Undefined property: Illuminate\Support\Collection::$election_name
happens, How to solve the problem?
There's a combination of problems that I would fix in order to bring clarity to your code and explain to you the problem. First of all in your code you have:
foreach ($election_list as $election_list)
I'll rename the variable for you to see:
foreach ($foo as $foo)
So what this does is that inside the foreach loop you will get all the values one by one, like expected but every time you store it to the initial variable. And once you are done with the foreach or break out of it earlier the $election_list will have the last used value. It might have unexpected results if you're trying to use the same $election_list later again. So I would suggest to use a differet variable names perhaps like $election_list as $election
Next, it's a little bit unclear why you would track the $index of the new elements by yourself. Instead you could just push into the array like this:
$my_election[] = $newObj
Actual error message:
Now for the actual error message: ->get() returns a Collection. So in the end you have an array full of Collections. So inside the for loop when you do $election_list[$i] - this will actually be a Collection object instead of the Model and thus the exception.
->get() will always get you the collection. For example with methods like ->first() and find/findOrFail you would get a single model. These functions might also be more appropriate to use since we are requesting with and id anyway.
Additionally, if this question is not a simplified version of your code then what I think you should actually do inside the controller:
$my_election = DB::table('election')
->whereIn('id', $election_list->pluck('election_id')) // pluck will give all the id's
->get();
This way you have a Collection of models assigned to $my_election.
guys, I'm trying to get the last element from the data returned to me but the problem is that it is throwing me an error which is
Call to undefined method Illuminate\Database\Query\Builder::last()
Here is my code
$last_saved_snapshot = \EnginePerformanceTestSnapshot::where('engine_performance_test_id', $id)->last();
Please tell me what is it that I'm doing wrong. Thanks
P.S I'm using Laravel 5.0
Try something like that:
$last_saved_snapshot = \EnginePerformanceTestSnapshot::where('engine_performance_test_id', $id)
->get()
->last();
The last method call is not working because namespace Illuminate\Database\Eloquent; does not have any last() method. The right way to do this is to do something like this:
$last_saved_snapshot = EnginePerformanceTestSnapshot::query()
->where('engine_performance_test_id', $id)
->orderBy('id', 'desc')
->first();
Otherwise, you need to get all items, since last() is part of the collection class so it expects a collection or array to be able to work and not a query builder. It is less efficient and a bad practice to fetch all data just for one.
I found another way to do it and that is:
$last_saved_snapshot = \EnginePerformanceTestSnapshot::where('engine_performance_test_id', $id)->orderBy('id', 'desc')->first();
This is working but if somebody can tell me why is the last not working then that would be a great help. Thanks
Try this, less code:
\EnginePerformanceTestSnapshot::
where('engine_performance_test_id', $id)
->latest()
->first();
I have a search in Laravel 4. After search for sh my url is this:
http://localhost/musiter/product/search-products/24?query=sh
I also have pagination there, but the pagination for the second link for example is:
http://localhost/musiter/product/search-products/24?page=2
instead of:
http://localhost/musiter/product/search-products/24?query=sh&page=2
Any way to fix this?
The code you're looking for is:
$paginator->appends(['query' => $value])->links();
You can add to the query string of pagination links using the appends method on the Paginator:
<?php echo $users->appends(array('sort' => 'votes'))->links(); ?>
This will generate URLs that look something like this:
http://example.com/something?page=2&sort=votes
If you wish to append a "hash fragment" to the paginator's URLs, you may use the fragment method:
<?php echo $users->fragment('foo')->links(); ?>
This method call will generate URLs that look something like this:
http://example.com/something?page=2#foo
You can also check [Laravel documentation].1
I have two custom components that reference an external database. In component1 I set the parameters necessary to connect to that external DB.
Is there I way that I can use the parameter set in component1 within component2?
my code within my model in component2:
$app = JFactory::getApplication();
$params = $app->getParams('com_component1');
advises me of a fatal error:
Fatal error: Call to undefined method JApplicationAdministrator::getParams() in /var/www....
Should I just stop being lazy and redefine the same parameters in component2, or is there a reasonable solution?
Try using the following code.
$params = JComponentHelper::getParams('com_component1');
$test = $params->get('param_name');
To get parameters, you need to use JComponentHelper, not JFactory.