Problem in Creating Simple Form in Zend - zend-form

I am new on Zend Framwork(MVC). I want to crate simple a Form with some HTML control.
I have create one controller IndexController, code are as follows:
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
/*$this->view->var = 'User Login Page';*/
$form = new Form_Login();
$this->view->form=$form;
}
}
And my Form's code in application/forms/Login.php:
<?php
require_once('Zend/Form.php');
class Form_Login extends Zend_Form
{
public function init()
{
parent::__construct($options);
// the code bellow will create element
$username = $this->CreateElement('text','username');
$username->setLabel("Username:");
// and
$submit= $this->CreateElement("submit","submit");
$submit->setLabel("Submit");
// now add elements to the form as
$this->addElements(array(
$username,
$submit
));
}
}
?>
When i run this project then its show an error like this:
**Fatal error: Class 'Form_Login' not found in C:\xampp\htdocs\LoginForm\application\controllers\IndexController.php on line 16**
Please help me...
Thanks
Pankaj

Everything looks good, make sure your Login.php file has this as the first lines:
<?php
class Form_Login extends Zend_Form
{
public function init()
If that doesn't help, you might want to check your index.php/Bootstrap.php files and server configuration to make sure all paths are correct.

Related

Laravel controller based api routing

My normal web app runs w/o any issue. Then I wanted to experiment with APIs. I enabled Passport since I need api authorization (but at this moment, I rather want to get this thing working and I have no idea whether it is a problem with Passport) and I wanted to get simple json output of specific Product. So far, I was not able to get it working. I'll describe contents of each file and if someone can direct me to find the issue in my code, that would be great.
Resources\Product.php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class Product extends JsonResource
{
public function toArray($request)
{
return parent::toArray($request);
}
}
Providers\AuthServiceProviders.php
public function boot()
{
$this->registerPolicies();
Passport::routes();
}
User.php
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
...
}
ProductController.php
class ProductController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function apiShow(Product $product)
{
return new ProductResource($product);
}
...
}
routes/api.php
Route::get('/products/{product}', 'ProductController#apiShow');
Now if I go to http://localhost/public/products/1, it displays the page as expected. But if I type in http://localhost/public/api/products/1, it will always go to home page which is set to localhost/public in HomeController.
If I modify routes/api.php as:
Route::get('/products/{id}', function($id) {
return Product::find($id);
});
I get the correct json output in the browser.

Parent Theme not follow in the controller template prestashop

Hi I have created a controller in which I am setting the template. It is a front controller. The problem I am getting is that the parent theme is not followed in the controller rather I just get another page uniquely all by itself and by the looks of it it is like that the template is not attached to the module. Currently the controller is just basic. I am beginner. I have attached the controller code. The code of my tpl file is also added. I have attached an image to show the problem.I haven't done any changes elsewhere just calling the controller from the module.php file by the link. Thank you in advance.
//controller code
class ExperimentFirstPageModuleFrontController extends ModuleFrontController
{
public $ssl = true;
public function __construct()
{
$this->bootstrap = true;
parent::__construct();
$this->context = Context::getContext();
}
public function initContent()
{
parent::initContent();
$this->context->smarty->assign(array());
$this->setTemplate('module:experiment/views/templates/front/list.tpl');
}
public function setMedia()
{
parent::setMedia();
$this->addjQuery();
}
}
//tpl file
<h>hello</h>

prestashop 1.6 custom page don't work?

I have create a Test controller using the code in : Create Custom page in Prestashop 1.5.3.1
class MyPageController extends FrontController
{
public $php_self = 'mypage';
public function init() {
parent::init();
}
public function initContent() {
parent::initContent();
die('test!');
}
}
I put it in the /controllers/front/MyPageController.php and it does not work. i get a clean html page.
What am I missing ?
link to custom page : http://www.funtoy.co.il/index.php?controller=MyPage
Edit 1 :
fix the semicolon at $php_self = 'mypage';
Thanks.
yaniv abo
Remove cache/class_index.php to clear the cache.

Prestashop ModuleAdminController use simple template

Trying to figure out why something like the below cant work. There is a tab in the preferences admin section that points to this controller but when going to it it always output a blank page. I have tried several things but the below is basically what I need. There is no MODEL... I simply need this to get the uploaded file for postProcessing...
The controller file...
class AdminAstroImporterController extends ModuleAdminController {
public function initContent() {
parent::initContent();
return $this->display(__FILE__, 'import.tpl');
}
public function postProcess() {
//do something here
}
}
Looks like you can overide the actual content output by doing as shown in the initContent() function shown below. The 'content' in the smarty assign can be any html you generate yourself.
class AstroImporterAdminController extends AdminController {
public function __construct() {
parent::__construct();
//load current settings
$this->data = unserialize(Configuration::get('ASTRO_IMPORTER'));
}
public function initContent() {
parent::initContent();
$this->show_toolbar = false;
$this->context->smarty->assign(array(
'content' => $this->renderSettings().$this->renderForm().$this->displayFields(),
));
}
I found that this works:
public function renderList()
{
global $currentIndex, $cookie;
$smarty = $this->context->smarty;
$smarty->assign('currentIndex', $currentIndex);
return $this->context->smarty->fetch($this->getTemplatePath().'/main.tpl');
}
Although its dirty as hell, it seems cleaner than Amb3rL4nn answer.
In v1.4 it was very easy to create a tab (and easy to find documentation) I wonder why they changed it and didn't supply an docs.

creation of model object in controller yii

can any one tell me how to create a model object inside a constructor in yii. I had written the code as belo
<?php
class DistributorsController extends Controller
{
public $layout = '//layouts/column4';
public $defaultAction = null;
public function __construct()
{
echo '<br>Into constructor';
parent::__construct('Distributors','distributors');
}
public function actionDistributors()
{
$this->render("ChannelMask");
}
}
?>
But it is displaying only "Into constructor" string and view is not showing in my browser.
You need to call a model into the Controller.
Create a model, then in Controller, call it like :
Distributor::model()->findAll($criteria); //many models
or
Distributor::model()->findById($id); // one model
Like any other place if you want to create a new model:
$model = new Distributors();
or
$model = $this->loadModel($id, 'Distributors');
if you want to populate your model with existing data, then:
$model = Distributor::model()->findAll(); // all there is
or
$model = Distributor::model()->findByPk($id); // find by primary key