How does the JMicrodata function work in Joomla? - joomla

I read this officail Joomla article about Microdata: http://docs.joomla.org/Microdata
I tried put this meta element in the head section of my Joomla website:
<meta itemprop="name" content="title of your content">
By this code:
$scope="itemprop";
$property="name";
$content="title";
JMicrodata::htmlMeta($content, $property, $scope = '', $inverse = false);
But no success! Can somebody tell me whats the wrong?

Solutions
To add this meta tag in you <head> section of a Joomla website:
<meta itemprop="name" content="title of your content">
You can use one of the following solutions
1) Add this code in the <head> section:
echo JMicrodata::htmlMeta($content = 'title', $property = 'name');
2) In whatever part of your code/file you want:
$microdata = JMicrodata::htmlMeta($content = 'title', $property = 'name');
$document = JFactory::getDocument();
$document->addCustomTag($microdata);
Documentation help
JMicrodata::htmlMeta() is used for output microdata semantics in a meta tag, this method does not add the meta tag in the <head> section.
I see you use $scope="itemprop", which is wrong, the scope is used to specify the Type of microdata, here you can find the full list of the available Types http://schema.org/docs/full.html
I suggest you to use an instance of JMicrodata, this way you don't need to worry that microdata is displayed properly.
$microdata = new JMicrodata('Article');
echo $microdata->content('title')->property('name')->display('meta');

In the <head> section add
<?php
$property="name";
$content="title";
echo JMicrodata::htmlMeta($content, $property, '', false);
?>
That will definitely get you the metadata.
Elsewhere if you did
$property="name";
$content="title";
$microdata = JMicrodata::htmlMeta($content, $property, '', false);
$document = JFactory::getDocument();
$document->addCustomTag($microdata);
That should do the trick.

Related

PDF Filename Always 0 when viewing

I have created a function where a user can go to this link and he can view his bill in PDF. It's working but the name is always . Here's my code:
function export_view($account_number_id, $subaccount_number_id){
$pdf = $this->pdf($account_number_id, $subaccount_number_id);
$filename = $pdf->name.'.pdf';
$path = public_path($pdf->path);
$response = Response::make(file_get_contents($path), 200);
$response->header('Content-Type', 'application/pdf');
$response->header('Content-Disposition', 'inline; filename="'.$filename.'"');
return $response;
}
I also did manual pdf filename to see if it's the issue but it's the same. When I download it in my local, the name is there. What could I be doing wrong?
I'm guessing your $this->pdf() method renders the pdf from a blade template?
You can set the name of the PDF document in the html title metatag:
<head>
<title>{{ $invoice->number }}</title>
</head>

Codeigniter - Query inside foreach

So i'm using latest Codeigniter and my problem is that i have this situation where i should use query inside foreach in controller. I have view that shows all production orders in one list, and i want all user made comments and notes underneath them from other table. Quite general situation in coding, but how i should do this with Codeigniter, cause you should keep your SQL clauses in Models.
Before i just fork raw SQL inside controller, i wanted to ask what is more gentle and proper way to achieve this. Thanks!
Controller
<?php
public function show()
{
$this->load->database();
$this->load->model('report_model');
$this->load->helper('url');
$data['productionOrders'] = $this->report_model->getAllProductionOrders();
$this->load->view('all_reports', $data);
}
?>
Model
<?php
function getAllProductionOrders()
{
$this->db->select(*);
$this->db->from('dbo.QualityControl_ProductionOrders');
$query = $this->db->get();
return $query->result();
}
?>
View
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<?php
foreach ($productionOrdersas $row)
{
?>
<div>
ProdNo: <?php echo $row->Prodno; ?>
Descriptions:
Hours:
etc etc etc etc
</div>
[I want here comments and all user made notes]
<?php
}
?>
</body>
</html>
You should make an effort to avoid spinning over a result set with additional queries like that..imagine if you had 500 production orders. That's 501 queries to make a simple report
Instead, use a join & parse your results either by only printing out the header info once or using Underscore.php to make a nested result, as demonstrated here:
http://codebyjeff.com/blog/2012/08/no-more-machine-gunning-use-underscore-php
Not sure what you asking but try this -
In controller ,
$data['productionOrders'] = $this->report_model->getAllProductionOrders();
foreach($data['productionOrders']['id'] as $id)
{
$data['comment'][$id] = $this->report_model->getCommantsByOrderId($id);
}

How to change the page title name as product name in magento?

In my magento store have a small problem. I create one page title named as gold. In this page contain n number of products. If the customer click the product then change the page title name to product name.
Is there any possible to change it. I resolved this problem in php. But no luck in magento.
Here is the php code.
<?php
ob_start (); // Buffer output
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test</title>
</head>
<body>
<?php
$pageTitle = 'New Test'; // Call this in your pages' files to define the page title
?>
</body>
</html>
<?php
$pageContents = ob_get_contents (); // Get all the page's HTML into a string
ob_end_clean (); // Wipe the buffer
// Replace <!--TITLE--> with $pageTitle variable contents, and print the HTML
echo str_replace ('Test', $pageTitle, $pageContents);
?>
Thanks
In Magento you can change the Page Title like this:
$headBlock = $this->getLayout()->getBlock('head');
$headBlock->setTitle($newtitle); //set title
$headBlock->setKeywords($keywords); //set keywords
$headBlock->setDescription($description); //set description

Redirecting to another page. How do I display a countdown?

I'm just wondering if the following is possible:
I don't know anything about JQuery and I don't know how to make my own javascripts yet.
When a user logs into my website, they'll get a page that says "login completed".
Under that sentence, I would like to get a sentence that counts down the seconds until they are redirected. Is there a simple way to do this?
I already have a countdown function:
When the function is first called, the view 'view_login_success' is loaded and the $data[] array is passed to it. $data['sec'] holds the seconds remaining that should be printed on the screen.
When the do-while loop is over, the user should be redirected to the homepage.
What happends is, the 'view_login_success'-view isn't loaded at all and after 5 seconds, the user is redirected to the homepage.
function timerIn() {
$now = time();
$this->load->view('view_login_success', $this->data);
do {
if (time() - $now != 0) {
$this->data['sec'] = $this->data['sec'] - 1;
$this->load->view('view_login_success', $this->data);
$now = time();
}
} while ($this->data['sec'] != 1);
$this->data['sec'] = 5;
redirect('user/start');
}
Here is the view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login geslaagd</title>
<?php $this->load->view('templates/header2'); ?>
</head>
<body>
<h2 style="text-align: center;"><?php echo strtoupper(substr($this->session->userdata('gebruikersnaam'),0,1));
echo substr($this->session->userdata('gebruikersnaam'),1); ?>, U bent ingelogd!</h2>
<p>U word doorverwezen: <?php echo $sec; ?> seconden...</p>
</body>
<?php $this->load->view('templates/footer'); ?>
If there's a way to do this in JQuery of Javascript, then please explain to me what I should do to get it to work.
Thanks in advance! :)
That's not how php works.
If you want the page to redirect after 5 secs you have to do so in the JS code.
You redirect the user without sending the view to the client.
Right now you are only waiting 5 seconds to redirect. So:
Show the view
The JS will have the timer and then redirects.
The javascript code would be something like this:
setTimeout(function(){
window.location.href = 'theURLyouwant';
},5000)
OR you could use the ol' meta tag
<meta http-equiv="refresh" content="5; URL=theURLyouwant">
Use code-igniter to solve this problem. Use this reference class output. Output class will be loaded automatically. You don't need to load this. Use this function to set header.
$this->output->set_header('refresh:time-to-redirect; url='.site_url("your-url"));
For more detail about this class.

CodeIgniter and layouts? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What CodeIgniter library can provide this funcionality??
http://media.railscasts.com/videos/008_content_for.mov
It seems so simple on rails but I just cant find a simple way to achieve this on codeigniter.. please help.. I hate having to insert my styles or javascript in the body of the document
I hate templates like Smarty or http://williamsconcepts.com/ci/codeigniter/libraries/template/
Using my own implementation of Zend-like layout.
Add hook /application/hooks/Layout.php:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/**
*
*/
class Layout {
function render() {
global $OUT;
$CI = & get_instance();
$output = $CI->output->get_output();
if (!isset($CI->layout)) {
$CI->layout = "default";
}
if ($CI->layout != false) {
if (!preg_match('/(.+).php$/', $CI->layout)) {
$CI->layout .= '.php';
}
$requested = BASEPATH . '../application/layouts/' . $CI->layout;
$default = BASEPATH . '../application/layouts/default.php';
if (file_exists($requested)) {
$layout = $CI->load->file($requested, true);
} else {
$layout = $CI->load->file($default, true);
}
$view = str_replace("{content}", $output, $layout);
$view = str_replace("{title}", $CI->title, $view);
$scripts = "";
$styles = "";
$metas = "";
if (count($CI->meta) > 0) { // Массив с мета-тегами
$metas = implode("\n", $CI->meta);
}
if (count($CI->scripts) > 0) { // Массив со скриптами
foreach ($CI->scripts as $script) {
$scripts .= "<script type='text/javascript' src='" . base_url() . "js/" . $script . ".js'></script>";
}
}
if (count($CI->styles) > 0) { // Массив со стилями
foreach ($CI->styles as $style) {
$styles .= "<link rel='stylesheet' type='text/css' href='" . base_url() . "css/" . $style . ".css' />";
}
}
if (count($CI->parts) > 0) { // Массив с частями страницы
foreach ($CI->parts as $name => $part) {
$view = str_replace("{" . $name . "}", $part, $view);
}
}
$view = str_replace("{metas}", $metas, $view);
$view = str_replace("{scripts}", $scripts, $view);
$view = str_replace("{styles}", $styles, $view);
$view = preg_replace("/{.*?}/ims", "", $view); // Подчищаем пустые неподгруженные части шаблона
} else {
$view = $output;
}
$OUT->_display($view);
}
}
?>
Then enable hooks in your /application/config/config.php:
$config['enable_hooks'] = TRUE;
After that add to /application/config/hooks.php:
$hook['display_override'][] = array('class' => 'Layout',
'function' => 'render',
'filename' => 'Layout.php',
'filepath' => 'hooks'
);
Create folder /application/layouts/
Create file /application/layouts/default.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>{title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
{metas}
{scripts}
{styles}
<link rel="icon" href="<?= base_url() ?>favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<?= base_url() ?>favicon.ico" type="image/x-icon" />
</head>
<body>
<div class="head">
{head}
</div>
<div class="content">
{content}
</div>
</body>
</html>
Use it from controller:
class main extends MY_Controller {
function __construct() {
parent::Controller();
$this->parts[head] = $this->load->view("frontend/global/header.php", null, true);
$this->scripts = array("JQuery/jquery-1.4.2.min", "JQuery/form", "Core", "Frontend");
$this->styles = array("style");
$this->title = "Blah blah";
}
function index() {
$this->load->view('frontend/index.php');
}
}
I've achieved this in the past using this Template Library. From the documentation:
The Template library, written for the
CodeIgniter PHP-framework, is a
wrapper for CI’s View implementation.
Template is a reaction to the numerous
questions from the CI community
regarding how one would display
multiple views for one controller, and
how to embed “views within views” in a
standardized fashion. In addition,
Template provides extra Views loading
capabilities, the ability to utilize
any template parser (like Smarty), and
shortcuts for including CSS,
JavaScript, and other common elements
in your final rendered HTML.
Specifically, check out the library's additional utilities. It allows you to put something like this in your controller:
$this->template->add_js('js/YourJavascriptFile.js');
or
$this->template->add_js('alert("Hello!");', 'embed');
Echo $_scripts in your template
(preferably in the <head> section) to
utilize JavaScript added via this
method.
Similarly, you can do the same with your CSS:
$this->template->add_css('css/main.css');
$this->template->add_css('#logo {display: block}', 'embed', 'print');
..and simply echo $_styles in your <head> section.
Hope that helps.
Check out Twig - it supports "inheritance" (instead of the traditional include header, include footer, etc)
http://www.twig-project.org/
CodeIgniter helper:
http://github.com/jamiepittock/codeigniter-twig
or
http://github.com/MaherSaif/codeigniter-twig
(haven't tried either, but looks like the latter is a fork w/the latest commits)
I had the same problem with finding a advance layout library as well,
so i wrote my own version which also fits your need (using YAML file).
Features
Manage layouts, page title, metas, css and js with YAML file for cleaner and lighter controllers.
Default configs can be overwritten in controller configs. So that you can split your css and js into smaller files for more flexible design.
Combine and minify css and js files in production mode for faster page loading.
Usage
// in the controller
$this->view->render();
This lib will get the layout, view, page title, css, js, metas from your YAML configs
Documentation
Please see this post for more detail
download
Download source code from Github

Resources