I am trying to display a tree of categories and subcategories by using dijits with zend framework. Haven't been able to find a good example. This is what I've got:
Basically I got the following code as my action:
class SubcategoriesController extends Zend_Controller_Action{
.....
public function loadtreeAction()
{
Zend_Dojo::enableView($this->view);
Zend_Layout::getMvcInstance()->disableLayout();
//Creating a sample tree of categories and subcategories
$a["cat1"]["id"] = "id1";
$a["cat1"]["name"] = "Category1";
$a["cat1"]["type"] = "category";
$subcat1 = array("id" => "Subcat1","name" => "Subcategory1" , "type" => "subcategory");
$subcat2 = array("id" => "Subcat12","name" => "Subcategory12" , "type" => "subcategory");
$a["cat1"]["children"] = array($subcat1,$subcat2);
$treeObj = new Zend_Dojo_Data('id', $a);
$treeObj->setLabel('name');
$this->view->tree = $treeObj->toJson();
}
....
}
And on my view:
<?php
$this->dojo()->requireModule('dojo.data.ItemFileReadStore');
$this->dojo()->requireModule('dijit.Tree');
$this->dojo()->requireModule('dojo.parser');
?>
<div dojoType="dojo.data.ItemFileReadStore" url="/Subcategories/loadtree" jsId="store"></div>
<div dojoType="dijit.tree.ForestStoreModel" jsId="treeModel" store="store" rootId="root" rootLabel="List of Categories" childrenAttrs="children" query="{type:'category'}"></div>
<div dojoType="dijit.Tree" model="treeModel" labelAttrs="ListOfCategories"></div>
It doesn't even seem to try to load the tree at all.
Any help is appreciated
First you must create separate action. One for display, other to load:
public function indexAction()
{
Zend_Dojo::enableView($this->view);
$this->view->dojo()->setDjConfigOption('parseOnLoad', true);
}
public function loadtreeAction()
{
//Creating a sample tree of categories and subcategories
$a["cat1"]["id"] = "id1";
$a["cat1"]["name"] = "Category1";
$a["cat1"]["type"] = "category";
$subcat1 = array("id" => "Subcat1","name" => "Subcategory1" , "type" => "subcategory");
$subcat2 = array("id" => "Subcat12","name" => "Subcategory12" , "type" => "subcategory");
$a["cat1"]["children"] = array($subcat1,$subcat2);
$treeObj = new Zend_Dojo_Data('id', $a);
$treeObj->setLabel('ListOfCategories');
$this->view->tree = $treeObj->toJson();
}
And you dont must forget the
setDjConfigOption('parseOnLoad', true)
In your views/scripts/index.phtml (if you use layout, some parts must be placed in, i let you do that) :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<?php
$this->dojo()->enable();
$this->dojo()->requireModule('dojo.data.ItemFileReadStore');
$this->dojo()->requireModule('dijit.Tree');
$this->dojo()->requireModule('dojo.parser');
echo $this->dojo();
echo $this->dojo()->addStylesheetModule('dijit.themes.tundra');
?>
</head>
<body class="tundra">
<div id="content">
<div dojoType="dojo.data.ItemFileReadStore" url="http://194.79.142.38:1080/rbplm/public/home/index/loadtree" jsId="store"></div>
<div dojoType="dijit.tree.ForestStoreModel" jsId="treeModel" store="store" rootId="root" rootLabel="List of Categories" childrenAttrs="children" query="{type:'category'}"></div>
<div dojoType="dijit.Tree" model="treeModel" labelAttrs="ListOfCategories"></div>
</div>
</body>
</html>
And in loadtree.phtmln just:
<?php echo $this->tree ?>
Related
I'm using CI version 3 and I'm using the built in email functionality to send an HTML email template.
My code is as following:
public function send_email($sendTo, $fromName, $fromEmail, $data, $subject) {
$this->email->set_mailtype('html');
$this->email->from($fromEmail, $fromName);
$this->email->to($sendTo);
$this->email->subject($subject);
$this->email->attach(FCPATH . "images/logo.png", "inline");
$content = array(
'HTMLcontent' => $data
);
$body = $this->load->view('email_template.php', $content, TRUE);
$this->email->message($body);
if ($this->email->send()) {
return TRUE;
} else {
return FALSE;
}
}
The FCPATH is ok it shows : /home/myuser/public_html/ and I have images folder inside public_html
email_template.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table>
<tr>
<td>
<a href="" target="_blank">
<img src="cid:logo.png" width="144" height="76" border="0" alt="logo"/>
</a>
</td>
</tr>
</table>
</body>
</html>
When the email comes it shows with a missing logo as the image below
controller:edit_details
public function index()
{
$this->load->model('edit_details_model'
$this->load->view('edit_details_view',$data);
}
public function editdetails($id)
{
$this->load->model('edit_details_model');
$data['value']=$this->edit_details_model->edit_data($id);
$this->load->view('edit_details_view',$data);
}
public function update_details()
{
$this->edit_details_model->update_data();
$this->getall();
}
}
model: edit_details_model
public function _construct()
{
parent::construct();
$this->load->database();
$this->load->helper('form');
}
public function edit_data($id)
{
$collection = $this->mongo_db->db->selectCollection('employee');
$query=$collection->findOne( array( '_id' => ($id)) );
return $query;
}
}
view:edit_details_view
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
//collection = $this->mongo_db->db->selectCollection('employee');
// $cursor=$collection->findOne( array( '_id' => new MongoId($id)) );
if (is_array($value) || is_object($value))
{
foreach($value as $document)
{
$id=$document["_id"];
$name=$document['name'];
$email=$document['email'];
$phone=$document['phone'];
}
}
?>
<form role="form" name="frm1" method="post" ><?php echo form_open('edit_details/update_details')?>
NAME<input type="text" name="ntxt" value="<?php echo $name;?>" /><br />
EMAIL<input type="etxt" name="etxt" value="<?php echo $email?>"/><br />
PHONE<input type="ptxt" name="ptxt" value="<?php echo $phone?>"/><br />
<input type="submit" name="submit" value="submit" />
</form>
</body>
it shows undefined name,email and phone in the from
try this
foreach($value as $document)
{
$id=$document->_id;
$name=$document->name;
$email=$document->email;
$phone=$document->phone;
}
Is there a way to use an svg element as an icon for the Microsoft.Maps.Pushpin?
I created an svg
element like this:
var fillcolor = "#ff0222";
var svg1 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg1.setAttribute("height",50);
svg1.setAttribute("width",50);
var circles = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circles.setAttribute("cx",25);
circles.setAttribute("cy",25);
circles.setAttribute("r",25);
circles.setAttribute("fill",fillcolor);
svg1.appendChild(circles);
On the Microsoft.Maps.Pushpin it is possible to set the options (PushpinOptions) where you can specify the htmlContent property to the value of your choice.
See: http://msdn.microsoft.com/en-us/library/gg427629.aspx
And the iSDK sample: http://www.bingmapsportal.com/isdk/ajaxv7#Pushpins15
The code should be inspired by something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Add pushpin with options</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: 'Your Bing Maps Key'});
}
function addCustomPushpin()
{
var pushpinOptions = {width: null, height: null, htmlContent: "<div style='font-size:12px;font-weight:bold;border:solid 2px;background-color:LightBlue;width:100px;'>Custom Pushpin</div>"};
var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), pushpinOptions);
map.entities.push(pushpin);
}
</script>
</head>
<body onload="getMap();">
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
<div>
<input type="button" value="AddCustomPushpin" onclick="addCustomPushpin();" />
</div>
</body>
</html>
I have an app on facebook, I am using only pagetabs, everything is going all right. I click like, I allow application, request permissions, I allow, but now it comes back to page and there is an error, it reloads over and over... The page cannot load because browser reloads it always, I don't know how to fix it...
Thanks very much
Here is my code:
<?php
require_once "sdk/facebook.php";
$app_id = "MY_APPID";
$app_secret = "MY_SECRET";
$is_fan = false;
// Init facebook api.
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
// Get and decode signed request.
$signed_request = $facebook->getSignedRequest();
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode(
'.', $_REQUEST['signed_request'], 2
);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(
base64_decode(strtr($payload, '-_', '+/'), true)
);
$signed_request = $data;
}
else {
$signed_request = false;
}
// Determine if we have a fan request.
if($signed_request) {
if($signed_request->page->liked) {
$is_fan = true;
}
}
// for fans
if ($is_fan) { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script>
var oauth_url = 'https://www.facebook.com/dialog/oauth/';
oauth_url += '?client_id=414328901957674';
oauth_url += '&redirect_uri=' + encodeURIComponent('https://www.facebook.com/pages/null/167838393340757/?sk=app_414328901957674');
oauth_url += '&scope=user_birthday,user_likes,photo_upload,publish_stream,user_about_me,user_photos,user_hometown,user_location'
window.top.location = oauth_url;
</script>
</head>
<body background="images/fanda.jpg" style="overflow:hidden;"">
</body>
<?php }
// for non-fans
else { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body background="images/klikni-like.jpg" style="overflow:hidden;">
</body>
<?php } ?>
When someone is a fan your script is always doing:
window.top.location = oauth_url;
This will cause the page to reload infinitely if someone is a fan.
I have found the solution to your problem. Update this when you check if($is_fan):
$user_id = $facebook->getUser();
if ($is_fan) {
if($user_id)
{
code after authentication and page Liked
}
}
else {
<script>
var oauth_url = 'https://www.facebook.com/dialog/oauth/';
................ Next 4 lines same as the above code ..............
</script>
}
I implemented a Zend project
And its working fine
Now i tried to implement a layout,
Step 1
for that i created a 'layout.phtml' in the folder 'application/layouts'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php echo $this->headTitle(); ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php $this->layout()->content ;?>
</body>
</html>
step2
Modified the application.ini and added the following line
resources.layout.layoutpath = APPLICATION_PATH "/layouts" under [production]
Step3
Modified the Bootstrap.php, and added the function '_initViewHelpers()'
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_AutoLoader(
array('namespace'=>'','basePath'=>APPLICATION_PATH)
);
return $moduleLoader;
}
function _initViewHelpers()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('Zend Framework Tutorial');
}
}
?>
Step4
I took the url in the browser http://localhost/zf_tutorial/public/
It showing the content of layout page but $this->layout()->content is not working (ie index action of index controller)
What is wrong with this code
You need to echo your content.
<?= $this->layout()->content ?> will do what you want!
You need to echo your content. Either you can use
<?= $this->layout()->content ?>
OR
<?php echo $this->layout()->content ?>