BootStrap.php:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initView()
{
// Initialize view
$view = new Zend_View();
$view->doctype('XHTML1_STRICT');
$view->headTitle('Book Store');
$view->headScript()->setFile('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
$view->headScript()->appendFile('../../js/jquery.pagination.js');
$view->headLink()->setStylesheet('../../css/style.css');
$view->headLink()->appendStylesheet('../../css/pagination.css');
$view->headLink()->appendStylesheet('../../css/formError.css');
$view = new Zend_View();
$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
return $view;
}
}
Index.phtml:
<?php echo $this->ajaxLink("Show me something",
"test",
array('update' => '#content'));?>
<div class="left_content">
<div class="title"><span class="title_icon"></span>Featured books</div>
<div class="title"><span class="title_icon"></span>New books</div>
<div class="new_products">
<div id="content"> </div>
<?php
$result=$this->result;
foreach($result as $bookName){
?>
<div class="new_prod_box">
<b> <?php echo $bookName['book']; ?></b>
<div class="new_prod_bg">
<span class="new_icon"><img src="../../images/new_icon.gif" alt="" title="" /></span>
<img src="../..<?php echo $bookName['pic']; ?>" alt="" title="" class="thumb" border="0" />
<input class="register" type="button" value="AddtoCart">
</div>
</div>
<?php
}
?>
</div>
<div class="clear"></div>
</div><!--end of left content-->
Here my ajaxlink() is not working it's redirect to "application error page".
Is the route "test" actually valid? since if it doesn't exist that would explain why you get an application error page
Related
I can't access image from file field in codeigniter view.In my project form helper is auto-loaded.When i check by form_validation it is found that image from file field is not reached at controller.
I got the message image not selected when i checked with form_validation and die function.
This is my view
<div id="content" class="clearfix">
<div class="contentwrapper"><!--Content wrapper-->
<div class="heading">
<h3>Manage images</h3>
</div><!-- End .heading-->
<!-- Build page from here: Usual with <div class="row-fluid"></div> -->
<div class="row-fluid">
<div class="span6" style="width:70%; margin-left:15%;">
<div class="box">
<div class="title">
<h4>
<span>Update Image</span>
</h4>
</div>
<?php echo form_open_multipart('productadmin/update_image');?>
<div class="form-row row-fluid">
<div class="span12">
<div class="row-fluid">
<label class="form-label span4" for="textarea">image<b style="color:#F00; font-size:11px;">*</b></label>
<input type="file" name="image">
<span class="error">
</span>
</div>
</div>
</div>
<div class="form-row row-fluid">
<div class="span12">
<div class="row-fluid">
<img src="<?php echo base_url();?>uploads/products/<?php echo $name;?>" width="50%" height="%">
</div>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-info" style="float:right;">Submit</button>
</div>
<?php echo form_close();?>
</div>
</div><!-- End .box -->
</div><!-- End .span6 --><!-- End .span6 --><!-- End .span6 -->
</div><!-- End .row-fluid --><!-- End .row-fluid --><!-- End .row-fluid --><!-- End .row-fluid -->
</div><!-- End contentwrapper -->
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js" type="text/javascript"></script>
<!-- End #content -->
<!-- End #wrapper -->
It is my controller
class Productadmin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('products_model');
$this->load->helper('security');
$this->load->helper('url');
if($this->session->userdata('activedata')!=true)
{
$this->session->set_flashdata('message','Please do login');
redirect('admin');
}
error_reporting(0);
}
public function update_image()
{
$id=$this->input->post('ids');
$newname=$this->input->post('image');
$this->form_validation->set_rules('image','Image','required');
$this->form_validation->set_error_delimiters('','');
if($this->form_validation->run()==false)
{
echo "image not selected";
die();
$this->template->load('adminhome','edit_image','');
}
else
{
echo "image selected";
die();
$config=array(
'upload_path'=>'./uploads/products/',
'allowed_types'=>'jpg|png',
);
$this->load->library('upload',$config);
$this->upload->do_upload('images');
$data=$this->upload->data();
$newimage=$data['file_name'];
echo $newimage;
die();
$this->products_model->update_single_image($id,$newimage);
redirect('productadmin/viewimages/'.$id);
}
}
}
pls help me
Change this rule :
$this->form_validation->set_rules('image','Image','required');
to this :
if (empty($_FILES['image']['name']))
{
$this->form_validation->set_rules('image', 'Image', 'required');
}
so when the image is not empty, the validation rule for that image will be skipped.
I've managed to show the prices for each product, but I can not show the star ratings for each product, this is a separate template file, I'm referencing the original list.phtml but something isn't right, I can only assume I'm missing something:
<div class="category-products">
<div class="products-grid">
<?php
$_helper = Mage::helper('catalog/output');
$categoryid = 26;
$category = Mage::getModel('catalog/category');
$category->load($categoryid);
$collection = $category->getProductCollection();
$collection->addAttributeToSelect('*');
foreach ($collection as $_product) {
?>
<div class="item">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<h2 class="product-name"><?php echo $_product->getName(); ?></h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?>
<?php
$product_block = new Mage_Catalog_Block_Product;
echo $product_block->getPriceHtml($_product);
?>
<div class="actions">
<?php if($_product->isSaleable()): ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</div>
</div>
<?php } ?>
</div>
The getReviewsSummaryHtml() is not showing the stars...
I installed a bootstrap theme for my yii application to be displayed on its login page.
How do I pass the information entered in these forms to the variables in login.php?
Also, how do I make the "Sign In" button in the theme to call the "Sign in" button in the login.php?
These are the forms in the bootstrap theme:
<div class="clearfix">
<input type="text" placeholder="username">
</div>
<div class="clearfix">
<input type="password" placeholder="password">
</div>
<button class="btn primary" type="submit">Sign in</button>
These are the forms that yii would display with its default theme in login.php:
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username'); ?>
<?php echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password'); ?>
<?php echo $form->error($model,'password'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Login'); ?>
</div>
for Yii best practice. Dont use login.php file instead use controller/action and in that action define your login logic like this:
Login View file
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username'); ?>
<?php echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password'); ?>
<?php echo $form->error($model,'password'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Login'); ?>
</div>
And this is your controller action:
public function actionLogin()
{
$model=new LoginForm;
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
if($model->validate() && $model->login()){
//Your Logic//
}
$this->render('login',array('model'=>$model));
}
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>array('login.php')
)); ?>
Normally Yii calls an action on a controller. Do you know the basics of Yii?
Cant figure the PROTOTYPE script for adding or removing a the css class name "selected" to img element based in click function (already done for Jquery...) but it must be in Prototype. And its driving me crazy. Cant make it work for prototype....
My original code is (Magento store)
<div class="block block-poll">
<div class="block-title">
<strong><span><?php echo $this->__('Community Poll') ?></span></strong>
</div>
<form id="pollForm" action="<?php echo $action ?>" method="post" onsubmit="return validatePollAnswerIsSelected();">
<div class="block-content">
<p class="block-subtitle"><?php echo $this->htmlEscape($poll->getPollTitle()); ?></p>
<?php if( $poll_answers ): ?>
<ul id="poll-answers">
<?php foreach( $poll_answers as $answer ): ?>
<li>
<input type="radio" name="vote" style ="display:none;" class="radio poll_vote" id="vote_<?php echo $answer->getId() ?>" value="<?php echo $answer->getAnswerId() ?>" />
<?php
$stripped = $answer->getAnswerTitle();
$stripped_final = str_replace(" ", "_", strtolower($stripped)); //Value (simplified)
?>
<span class="label"><label for="vote_<?php echo $answer->getId() ?>"><img src="http://www.passione.pt/media/poll/<?php echo $stripped_final; ?>.png" id="chooser" class="chooser" alt="<?php echo $this->htmlEscape($answer->getAnswerTitle()) ?>" onClick="document.getElementById('vote_<?php echo $answer->getId() ?>').checked =true;"/></label></span>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('poll-answers');</script>
<?php endif; ?>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Vote') ?>" class="button"><span><span><?php echo $this->__('Vote') ?></span></span></button>
</div>
</div>
</form>
</div>
<?php endif; ?>
For Jquery.
Could you transform for Prototype 1.7...?
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
var Chooser = $('#poll-answers img');
Chooser.click(function() {
$('.chooser').removeClass('selected');
if(!Chooser.hasClass('selected')) {
$(this).addClass('selected');
} else {
$(this).removeClass('selected');
}
});
</script>
Prototype version of that click handler (untested):
$('poll-answers').on('click', 'img', function(event, element) {
$$('.chooser').invoke('removeClassName', 'selected');
element.toggleClassName('selected');
});
Edit: Changed to toggleClassName as per #Victor's suggestion. +7 points for him, and from each to invoke thanks to #Geek Num. +7 points for him and 1 left over for me.
How do you integrate an accordian widget into a helloworld zend project? This is what I have so far and all I get is the page with the messages no accordians.
Bootstrap:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initView()
{
$view = new Zend_View();
//$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
$view->addHelperPath('Zend/Dojo/View/Helper/','Zend_Dojo_View_Helper');
$view->dojo()->addStylesheetModule('dijit.themes.tundra');
}
}
Layout File:
<?php echo $this->doctype() ?>
<html>
<head>
<?php echo $this->headTitle() ?>
<?php echo $this->headMeta() ?>
<?php echo $this->headLink() ?>
<?php echo $this->headStyle() ?>
<?php if ($this->dojo()->isEnabled()){
$this->dojo()->setLocalPath('/js/dojo/dojo.js')
->addStyleSheetModule('dijit.themes.tundra');
echo $this->dojo();
}
?>
<?php echo $this->headScript() ?>
</head>
<body class="tundra">
<?php echo $this->layout()->content ?>
<?php echo $this->inlineScript() ?>
</body>
</html>
View:
<?php // setup required dojo elements:
$this->dojo()->enable()
->setDjConfigOption('parseOnLoad', true)
->requireModule("dijit.layout.AccordianContainer")
->requireModule("dijit.layout.ContentPane")?>
<div style="width: 300px; height: 300px">
<div dojoType="dijit.layout.AccordionContainer" style="height: 300px;">
<div dojoType="dijit.layout.ContentPane" title="Heeh, this is a content pane">
Hi!
</div>
<div dojoType="dijit.layout.ContentPane" title="This is as well" selected="true">
Hi how are you?
</div>
<div dojoType="dijit.layout.ContentPane" title="This too">
Hi how are you? .....Great, thx
</div>
</div>
</div>