i want to fetch same template in cntroller - html

my index controller this and showing good html and header and footer is working correct but when i want to add method the css and html not working .
public function index()
{
$data['clients_list'] = $this->clients_model->get_all_clients();
$this->load->view('template/header');
$this->load->view('clients/index', $data);
$this->load->view('template/footer');
}
this is my add method where i want to add html as header and footer
public function add()
{
$this->load->view('template/header');
$this->load->view('clients/add');
$this->load->view('template/footer');
}

The way you are using $this->load->view() is not supported in the framework. You should only be loading one view. If you wish to include multiple views within a single view you must save them within the data to be rendered in the master view and echo them out within that view. To do this you use the third parameter of the view function explained at the codeigniter api: Very bottom of page
An example of this would be:
Controller:
function index(){
$data['clients_list'] = $this->clients_model->get_all_clients();
$data['header'] = $this->load->view('template/header', $data, TRUE);
$data['footer'] = $this->load->view('template/footer', $data, TRUE);
$this->load->view('clients/index', $data);
}
View:
<?php echo $header; ?>
<!-- YOUR INDEX PAGE CONTENT-->
<?php echo $footer; ?>
The third parameter of view() tells the framework to pre-render the view and output the contents as a string value which allows you to save as a variable and echo into the primary page.
Phil Sturgeon wrote a wonderful template library that I have been using in my projects that allows for a webforms style "master page" that you can have the rest of your views rendered inside of so that you do not have to build your header/footer view each time and inject it into every view.
Phil Sturgeon Template Library

Related

why the submit button is not working in laravel

I tried to edit the data form but the submit button doesn't work like it doesn't have a function. In that form I also added 1 more form which was wrapped in a modal
code of view:
code of controller:
public function update(Request $request)
{
$items = Arsip::where('field_id', Auth::user()->employee->field_id)->get();
$request->validate([
'indikator'=>'required',
]);
$i = $request->indikator;
foreach($i as $row) {
$i = indicator::find($row['id']);
$i->arsip_id = $row['arsip_id'];
$i->nama_indikator = $row['nama_indikator'];
$i->nilai_indikator = $row['nilai_indikator'];
$i->save();
}
return view('admin.approve.index', compact('items'))->with('success', 'update data successfully.');
}
Don't use images in questions
You're not very clear on what is or isn't working. It feels like your form action isn't correct. $items, seeing your code snippet` is a collection and not a single model, which would mean the route wouldn't be correct.
I would suggest using named arguments when building a route: route('arsip.update', ['id' => $item->id])
Also, you're nesting a form inside a form. This is not allowed within HTML, and there is no good reason for wanting to do this. I see that this is a delete button. You can hide a form somewhere else and use javascript or a button (outside a form) with a form attribute to submit the form. See this thread's answers for this approach.

Passing down MediaWiki template arguments to custom HTML attributes

Consider a custom MediaWiki extension that adds a new tag named simplified_example with some JavaScript (just calling alert with provided argument for simplicity):
<?php
if ( ! defined( 'MEDIAWIKI' ) ) die();
$wgExtensionFunctions[] = 'registerTags';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'myTags',
);
function registerTags() {
global $wgParser;
$wgParser->setHook('simplified_example', function ($input, $argv, $parser, $frame) {
$output = $parser->recursiveTagParse($input, $frame);
$title = $argv["value"];
return "<div onclick=\"alert('$title')\">$output</div>";
});
}
?>
Using that I can put following code in a MediaWiki page source:
<simplified_example value="Testing">...</simplified_example>
This results with ... div being clickable - a message box with provided text is displayed. Now I wanted to place this tag inside a template, like this:
<simplified_example value="{{{1}}}">...</simplified_example>
When I put this template into a MediaWiki page:
{{TestTemplate|Testing...}}
Once again I obtain a clickable ... but displayed message is not evaluated and {{{1}}} is displayed instead of provided Testing....
How can I pass the argument from MediaWiki page source down to my custom tag through a template?
Try to use #tag function instead of html in your template, like this:
{{#tag:simplified_example|value={{{1}}} }}

Yii2 mpdf with barcode-generator

I'm using yii2 and installed two extension : mpdf , and yii2-barcode-generator-8-types.
Both of them were installed and configured properly and working well.
But what I can't do is to load barcode into pdf.
Here is my code :
Controller :
public function actionPdf()
{
$pdf = Yii::$app->pdf;
$pdf->content = $this->renderPartial('_pdf');
echo $this->renderPartial('_pdf');exit;
return $pdf->render();
}
View :
<div id="showBarcode"></div>
<?php
use barcode\barcode\BarcodeGenerator as BarcodeGenerator;
$optionsArray = array(
'elementId'=> 'showBarcode',
'value'=> '12345678',
'type'=>'code128',
);
echo BarcodeGenerator::widget($optionsArray);
?>
And it show something like this
but If I try to delete all code inside actionPdf() and just write
return $this->render("_pdf");
it show like this:
Please help!!!
I think your controller should be this
public function actionPdf()
{
$pdf = Yii::$app->pdf;
$pdf->content = $this->renderPartial('_pdf');
return $pdf->render();
}
The row with echo $this->renderPartial('_pdf');exit; don't must be used because it prevents the program to invoke correctly the render of the pdf page. If you use this instruction you displays only the render of "html like code" page like you see in result you posted moreover immediately after this instruction you exit form action without invoking the $pdf->render.

How should I use requestAction in the view with CakePHP 3.x

My code:
// View/Activities/index.ctp
...
<div>
<?php echo $this->requestAction('/Activities/ajax_list/'.$categoryId,['return']);?>
</div>
...
//View/Activitest/ajax_list.ctp
....
<?php echo $this -> Html -> image("/img/add1.jpg"); ?>
...
<?php echo $this->Html->link('add_project', array('controller'=>'projects', 'action'=>'add', $categoryId)); ?>
....
I want to include the view 'ajax_list' into the 'index',and it has been displayed but the url of image and link was wrong.
Then I debug the Cake/Routing/RequestActionTrait.php , "requestAction" function I find "$request = new Request($params);" the $request->base , $request->webroot are null.
Could some one tell me how should I fix it?
The $base/$webroot properties not being set in the new request might be considered a bug, or maybe the docs are just missing a proper example solution, I can't tell for sure, you might want to report this over at GitHub and see what the devs say.
Use view cells instead of requestAction()!
Whenever applicable you're better off using view cells instead of requesting actions, as they avoid all the overhead that comes with dispatching a new request.
See Cookbook > Views > View Cells
No models involved? Use elements!
In case no models are involed, and all you are doing is generating HTML, then you could simply use elements.
See Cookbook > Views > Elements
Fixing requestAction()
A possible workaround would be to use a dispatcher filter that fills the empty $base/$webroot properties with the necessary values, something like
src/Routing/Filter/RequestFilterFix.php
namespace App\Routing\Filter;
use Cake\Event\Event;
use Cake\Routing\DispatcherFilter;
class RequestFixFilter extends DispatcherFilter
{
public function beforeDispatch(Event $event)
{
$request = $event->data['request'];
/* #var $request \Cake\Network\Request */
if ($request->param('requested')) {
$request->base = '/pro';
$request->webroot = '/pro/';
$request->here = $request->base . $request->here;
}
}
}
config/bootstrap.php
// ...
// Load the filter before any other filters.
// Must at least be loaded before the `Routing` filter.
DispatcherFactory::add('RequestFix');
DispatcherFactory::add('Asset');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
// ...
See also Cookbook > Routing > Dispatcher Filters > Building a Filter

Magento configuration - populating field when using frontend_model

I have specified a frontend_model in system.xml for an entry field. I did this because I wanted to make a field read-only. There may have been a more straightforward way to achieve that, but that's where I am at the moment. The thing is I cannot get the field to display the data it should.
I have a button that when pressed, populates the read-only field. That works fine. But when I hit 'Save Config', the data disappears from the field. The reason it disappears is because I can't find out what I should set the field's value to. Below tries using the getEscapedValue() method of Varien_Data_Form_Element_Abstract, but it returns nothing. And as usual with Magento, there is no documentation to speak of.
class Mypackage_MyModule_Block_Adminhtml_System_Config_DisabledText extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _prepareLayout()
{
parent::_prepareLayout();
if (!$this->getTemplate()) {
$this->setTemplate('mypackage/system/config/disabled_text.phtml');
}
return $this;
}
public function render(Varien_Data_Form_Element_Abstract $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$originalData = $element->getOriginalData();
$this->addData(array(
'my_value' => $element->getEscapedValue(),
'html_id' => $element->getHtmlId(),
));
return $this->_toHtml();
}
}
disabled_text.phtml contains the following:
<input id="<?php echo $this->getHtmlId() ?>" value="<?php echo $this->getMyValue(); ?>" class=" input-text" type="text" disabled/>
Thanks.
This is one of those places where you need to look at how Magento itself is doing something similar to what you want to do. If you look at the Mage_Adminhtml_Block_System_Config_Form_Field class's _getElementHtml
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
return $element->getElementHtml();
}
you can see that this method accepts a form element that's already been instantiated (based on what's in system.xml), and then this element renders itself with getElementHtml. That means when Magento needs to render (and, in turn, get the value) it does so in from the element object. Some crude debugging will let us know where getElementHtml can be located
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
var_dump(get_class($element));
return $element->getElementHtml();
}
Something like Varien_Data_Form_Element_Text will be dumped to the screen. In turn, this class inherits form Varien_Data_Form_Element_Abstract, which contains the following definition
public function getElementHtml()
{
$html = '<input id="'.$this->getHtmlId().'" name="'.$this->getName()
.'" value="'.$this->getEscapedValue().'" '.$this->serialize($this->getHtmlAttributes()).'/>'."\n";
$html.= $this->getAfterElementHtml();
return $html;
}
So, when Magento wants to get the value for a system config field, it uses the above PHP code to render the input. So, if you want to do the same in your template, I'd try something like this
Up in the class, assign a block property with the entire element. This is actually more efficient that plucking values out of the elements, since all PHP needs to store is an object reference.
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$this->setMyElement($element);
return $this->_toHtml();
}
Then, in the template, copy the code from magento's rendering, replacing the "$this" keyword with your saved element
<?php $_element = $this->getMyElement(); ?>
<!-- check the quoting/escaping on this html/php, I didn't actually run it, but the concept is sound -->
<input disabled="disabled" id="<?php echo $_element->getHtmlId();?>" name="<?php echo $_element->getName();?>"
value="<?php echo $_element->getEscapedValue();?>"
<?php echo $_element->serialize($_element->getHtmlAttributes());?>
/>
<?php echo $_element->getAfterElementHtml(); ?>
When you're working with Magento, try to think like a Magento developer. Instead of "I need to figure out how to make it do X", think "I need to add this feature to the store in the same way the rest of my teammates have". Then look how the core team did it, and copy their implementation, changing as little as you need to.
It does get easier the more you work with the system!