My custom block not showing header buttons on admin side in magento - magento

I am calling my block from controller but it doesn't display header buttons.I call my controller function with button click and create block using (
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_addanswer'));
$this->renderLayout();.
While on addanswer page i simply use the class
Mymodule_Block_Adminhtml_module_Edit_Tab_Addanswer extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
// code
}
}
It display data like the attach image
I want to add save or add like buttons but don't know from where i can do that.I added buttons from block or from edit.php but i don't know how i can add buttons from controller or in form direct.Is it possible ? Thanks in advance

You maybe missing
class CompanyName_Mymodule_Block_Adminhtml_Addanswer_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
public function __construct()
{
parent::__construct();
$this->_objectId = 'id';
$this->_blockGroup = 'addanswer';
$this->_controller = 'adminhtml_addanswer';
$this->_updateButton('save', 'label', Mage::helper('addanswer')->__('Save'));
$this->_updateButton('delete', 'label', Mage::helper('addanswer')->__('Delete'));
}
.....
Take a look # Custom Module with Custom Database Table

Related

Magento 1.9 custom admin grid load inside itself

I have 2 grids in the same module (and i need to keep them in the same module).
When i click on the top of the column the grid load itself inside itself.
Below is my code:
Myname_Blink_Adminhtml_BlinkController
public function keywordsAction()
{
$this->loadLayout();
$this->_setActiveMenu('blink/keywords');
$this->_addContent($this->getLayout()->createBlock('Myname_Blink_Block_Adminhtml_Keywords_Grid'));
$this->renderLayout();
}
my block file : Myname_Blink_Block_Adminhtml_Keywords_Grid extends
class Myname_Blink_Block_Adminhtml_Keywords_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('keywords_grid');
$this->setDefaultSort('keywords_id');
$this->setDefaultDir('ASC');
//$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
As suggested to this post: Multiple grid in Magento admin
I removed the files:
=>Myname_Blink_Block_Adminhtml_Keywords
=>app\design\adminhtml\default\default\layout\myname\blink.xml
Maybe something goes wrong with AJAX call.
Did you try this one:
http://davemacaulay.com/fix-issue-with-magento-adminhtml-grid-ajax-call-containing-the-whole-page/
public function keywordsAction()
{
if($this->getRequest()->isXmlHttpRequest()) {
$this->getResponse()->setBody($this->getLayout()->createBlock('Myname_Blink_Block_Adminhtml_Keywords_Grid')->toHtml());
return $this;
}
$this->loadLayout();
$this->renderLayout();
}
Good luck!!!

Laravel: master view or controller always called

How can I set a "default" view and/or controller so it will be always called no matter the route?
I have tried with:
(routes.php)
Route::get('/*', function(){
return View::make('master');
});
and:
Route::get('*', function(){
return View::make('master');
});
But gives me NotFoundHttpException;
Related question: Is there a better way to do this than setting it in the routes.php?
Thanks!
Laravel have something called Controller Layouts, then in your controller you can create a variable named $layout and set it to a master or default view:
class Controller extends BaseController
{
protected $layout = 'layout.master';
public function getIndex() {
$data[];
$this->layout->content = View::make('myview', $data);
}
Now in the layout.master view you can access the $content variable.

White Screen When posting in CodeIgniter

Codeigniter gives a white screen every time a form is posted:
Here is the controller logic [controllers/account.php]:
class Account extends CI_Controller
{
public function create()
{
if($this->input->post(NULL, TRUE)){
$params = $this->input->post();
//add validation layer
$accountOptions = array($params are used here)
$this->load->model('account/account', 'account');
$this->account->initialize($accountOptions);
$this->account->save();
}
$header['title'] = "Create Free Account";
$this->load->view('front_end/header', $header);
$this->load->view('main_content');
$content['account_form'] = $this->load->view('forms/account_form', NULL, TRUE);
$this->load->view('account/create', $content);
$footer['extraJs'] = "account";
$this->load->view('front_end/footer', $footer);
}
}
Here is the Account Model logic [models/account/account.php]:
class Account extends CI_Model
{
public function __construct()
{
parent::__construct();
}
public function initialize($options)
{
//initialize
}
}
The view first loads fine then after filling the form and clicking submit, just white page.
I tried to add __construct to the controller and load account/account from there, the form does not even load. Any ideas?
I just found the problem:
- The Model account has duplicated definition and the error_reporting was off!
You shouldn't have two classes with the same name Account (the controller and model). Check your server and/or Codeigniter log it should show up there.
I advise you to call your controller class Account and your model class M_Account. You can then rename the model to account whenever you load it, just like you did:
$this->load->model('account/m_account', 'account');
public function __construct()
{
parent::__construct();
$this->load->model("account/account");
}
you load model,library and helper files in construct dont load to inside a function

How to use multiple layouts inside the same controller?

I wanted to ask how can I define a multiple layouts for the same controller in Laravel.
The scenario here is like the following:
I have a controller Home and i have two actions in this controller one called steps and the other called login.
I want the both of them load different layout.
The way that I used to make this is as follow:
protected $layout = "layouts.page";
public function index()
{
// Get to the page of the website making steps
$this->layout->content = View::make('steps');
}
Can I define multiple layouts? Maybe passing an array as follow:
protected $layout = array('first' => "layouts.page", 'second' => 'layouts.second');
Best solution is to create a method to generate your view, nesting your multiples layouts :
return View::make('layouts.master', array())
->nest('section_one', YOUR_SECOND_MASTER, array())
->nest...
and stop setting protected $layout with a layout.
I achieve in this way
$this->layout = View::make('layout.master');
$this->layout->content = View::make('step.demo')
Use View Composers or look at the section passing sub-views to views under http://laravel.com/docs/responses#views.
You can also specify multiple sections for the layout that is defined at http://laravel.com/docs/templates#blade-templating
EDIT:
If you want to define a master layout for different views from the same controller, then define the layout on the View it self. Take a look at the section Using A Blade Layout
The #extends is used to define the layout on the view itself.
Hope this helps for what you are looking for.
If you look at the BaseController, which your controller likely extends, you'll see the layout variable is ultimately used simply as th e result of any old View.
In other words, your $layout variable is just a View. You can create any $layout variable in your controller:
<?php
class MyController extends BaseController {
protected $layout;
protected $layout_alt;
// Here we're over-riding setupLayout() from
// the BaseController
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
if ( ! is_null($this->layout_alt))
{
$this->layout_alt = View::make($this->layout_alt);
}
}
}
Then in your view, you can return:
$this->layout_alt->content = View::make('steps');
Of course, the possibilities are endless as Abishek R Srikaanth pointed out. You can do fancy things with Blade as well :D
The way i do this is quite similar to #fideloper's answer.
protected $layout;
private $_layout = null;
public function __construct()
{
}
private function _setupLayout()
{
if ( ! is_null($this->_layout))
{
$this->layout = View::make($this->_layout);
}
}
public function home() {
$this->_layout = 'layouts.1col_public';
$this->_setUpLayout();
$this->layout->content = View::make('static/home');
}
public function about() {
$this->_layout = 'layouts.2col_public';
$this->_setUpLayout();
$this->layout->active_menu = 'about';
$this->layout->content = View::make('static/default');
}
This isn't common practise, and I haven't tested it yet, but it's worth a try.
In your controller's method:
$this->layout = View::make('layouts.master1");

Loading codeigniter view with predefined variables

I do not know if the following is possible. If not other suggestions are appreciated.
In nearly all my controllers I will load some default views. For example header, footer and menu.
I would like to have certain variables auto load for each view.
If I take the header as an example. Into my header I will always load an array of $css scripts and an array of $javascript files.
$javascript[] = 'js/jquery.js';
$javascript[] = 'js/jqueryui.js';
But additionally, depending on the current page logic, I might want to add another javascript file to my $javascript variable.
$javascript[] = 'js/custom.js';
Then ideally, I would like these variables to be automatically inserted as data into the load of the view.
In other words, I just want to call:
$this->load->view('header');
How could this be achieved?
Create MY_Controller add a public array there then extend from MY_Controller
class MY_Controller extends CI_Controller {
public $data;
function __construct() {
parent::__construct();
$this->data['MYVAR'] = 'Something';
}
}
in your other controllers you just do it like this
class SomeClass extends MY_Controller {
function __construct () {
parent::__construct();
}
function index () {
$this->data['SomeOtherVar'] = 'xxx';
$this->load->view('viewname', $this->data);
}
}
You can use $this->load->vars in your Controller.
I use this in my_controller and all controllers are extend from MY_Controller
For example
<?php
class MY_Controller extends Controller{
public function __construct(){
parent::__construct();
$this->setGlobalViewVariables();
}
public function setGlobalViewVariables(){
$result = array();
$result['value1'] = 'value1';
$result['value2'] = 'value1';
$this->load->vars($result);
}
}
?>
you should create an hook for this, it is very simple

Resources