Views from the module won't display (CodeIgniter HMVC) - codeigniter-3

I'm actually working in an admin panel, and I want to manage all my sliders inside it,
so I created all the functions etc...
In the view file where I want to call the view from the module by running
<?php
echo Modules::run('sliders/_slider_display);
?>
But, The the sliders won't display, I will show you how I did it.
function _slider_display() {
$current_url = current_url();
$query_ads = $this->get_where_custom('target_url', $current_url);
$num_rows_ads = $query_ads->num_rows();
if($num_rows_ads>0){
$this->load->module('slides');
foreach($query_ads->result() as $row)
{
$parent_id= $row->id;
}
$data['query_slides']= $this->slides->get_where_custom('parent_id', $parent_id);
$this->load->view('sliders', $data);
}
}
as I mentioned, I tried to call the view in the homepage, but did not worked, I don't know what is the problem.
Thank you !

Related

Magento2 custom price render on product page

How to format the product view page price differently from the one from category page ( and possible others ) ?
If I change in my child theme the:
app/design/frontend/VENDOR/my_theme/Magento_Catalog/templates/product/price/final_price.phtml
The price is being changed on both pages (category and product);
I have tried several approaches but it seems that this price rendering mechanism is complicated as hell in Magento2.
Thanks!
<?php
try {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get(‘Magento\Framework\App\Action\Context’)->getRequest();
$currentPageXML = $request->getFullActionName();
echo $currentPageXML; //catalog_product_view is product detail page controller action
} catch (Exception $e) {}
?>
The above code will help you get the current area of the environment being accessed, and then you can apply a logic
if ($currentPageXML=="catalog_product_view") {
// render my custom need
} else {
// keep the actual code intact.
}
You are facing a problem because same phtml file is being used by both the catalog and product page, so a change in this file will be reflected everywhere.
I hope this will help you.

Where to put controller code for Yii2 sidebar modal form?

I want to have a modal Report Issue form in the sidebar that loads on every page. I can't seem to wrap my head around where to place the controller/form initialization code.
A typical controller action:
public function actionContact()
{
$model = new Feedback();
if ($model->load(Yii::$app->request->post()) && $model->sendEmail()) {
Yii::$app->getSession()->addFlash('success', 'Thank you for contacting us.<br /><br />We will respond as soon as possible.');
$model = new Feedback();
}
if (Yii::$app->request->isPjax) {
return $this->renderAjax('contact', [
'model' => $model,
]);
} else {
return $this->render('contact', [
'model' => $model,
]);
}
}
The $model is set when the action is first called, but if the modal is to be placed in the sidebar, every controller and/or controller/action could be called, and I don't want to have the $model initialization repeated each time (DRY).
I'm not sure if this is a prime condition for a custom widget, or a controller->beforeAction, or something else altogether.
Any insight is greatly appreciated.
Use a widget. The widget will create an empty $model and pass it to it's view. You can insert the widget in any view or in the layout too.
Regarding the
every controller and/or controller/action could be called
why would any controller be called? Your form should send the info to 1 controller/action not any of them. The widget will be shown by any controller/action but the widget's form will always just call 1.

pass the variable to child view in zend

I am using zend framwork
in my controller i have set string to display in view like
Controller
$this->view->foo = 'sample string or content';
main view
echo $this->foo;
this is working fine show me string sample string or contentbut when i call other view inside this main view its not give any output
i am caaling something like this view inside view.
<?=$this->myform;?>
in myform.phtml
echo $this->foo;
this is not given any output...
Please help me what i am going worng...
thanks
Use Partial Helper like this:
In view:
<?php echo $this->partial('myform.phtml', array('foo' => $this->foo)); ?>

Zend-form in controller and processing this form in specific action - how can I do this?

Im my layout I have search form, so it's displayed on every page.
It looks like this:
<?
$form = new SearchIndexForm();
$form->setAction($this->configuration['BaseUrl']Index/search);
echo $form; ?>
I would like to have sth like that: when someone click submit button, the form redirects to the action "search" on "Index" controller, where there is processing the form values.
So, what should I do, to have equivallent to this, which will be working with data send by post method from form in layout?
if($this->_request->isPost()){
$formValues = $this->_request->getParams();
if ($form->isValid($formValues)){
...
}
}
With the above, when I click submit, it gets me to the /Index/search, but nothing happens...
The form itself worked perfectly when it was in one action.
It seems like you're doing everything right but I think that there is some code that you should change.
Try the following code
$request = Zend_Controller_Front::getInstance()->getRequest();
//or you can try
//$request = $this->getRequest();
if($request->isPost()){
$form = new SearchIndexForm();
if ($form->isValid( $request->getPost() ) ){
echo 'This should output if the form is valid' . PHP_EOL;
}
}
I don't like accessing variables directly as you did in $this->_request because Zend might have to do doing things to the variables to make them 'proper'. I know that sometimes nothing is done but better safe than sorry. Unless you're positive about it, which I'm usually not positive about unless I've really looked at the code.

Way to define others layout() parts such layout()->content?

Ive done some search but no success.. i am trying to figure out how to define others layout() parts such layout()->content variable.. i would love to get int layout()->navigation (a custom one) which display the navigation..
Any ideas ?
Thanks.
Not sure if this is what you want, but you can create additional 'parts' of layout simply by assigning a value to your new part. ZF will take care of the rest. For example, in a bootstrap.php you could do:
public function _initNewLayoutPart() {
$view = $this->bootstrap('view')->getResource('view');
$view->layout()->newpart = 'some new part';
}
Then in your layout.phtml you could just echo the new part:
<?php echo $this->layout()->newpart; ?>
It is possible by just creating a new variable in layout, you can define it in your controller (preferably in init or postDispatch). Just like this:
public function init()
{
$this->view->layout()->motd = '<b>Message of the day.</b>';
}
Then in your actual view where you want to see the message, all you have to do is:
<?php echo $this->layout()->motd; ?>
If you want something fancier, such as rendering a whole page or sidebar, try the following:
public function init()
{
$this->view->layout()->sidebar = $this->view->action('render', 'sidebar');
}
With render being the action (including render.phtml) and sidebar being the controller.