Display Barcode for each Item in view Codeigniter using zend barcode framework - barcode-printing

I have to develop software for shop. i have list of product having their price and barcode digits. I want to show each and every items in product list html page along with barcode to take a print of barcode on stickers.
I googled about the zend barcode rendering and i tested also and found result ok with one barcode but here is my mai problem arise that i want to generate multiple barcode in foreach loop on my view->page.
I am very new to codeigniter please help.
My Controller 'Barcode.php'.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Barcode extends CI_Controller {
public function __construct(){
parent::__construct();
if($this->session->userdata('successful_logged_in')){
//load library
$this->load->library('zend');
//load in folder Zend
$this->zend->load('Zend/Barcode');
$this->load->model('common_model');
}
else{
redirect('login','refresh');
}
}
public function index(){
//Generate 13 digit random number to render barcode
$temp = rand(1111111111111,9999999999999);
$this->set_barcode($temp);
$table='item_master';
$order_by='name ASC';
$data['item_list']=$this->common_model->select_active_records($table,$order_by);
$this->load->view('home/header');
$this->load->view($this->router->fetch_class().'/records',$data);
$this->load->view('home/footer');
}
public function set_barcode($code){
//generate barcode
Zend_Barcode::render('code128', 'image', array('text'=>$code), array());
}
In my View 'records.php'.
<tbody>';
$i=1;
if($item_list==false){
echo '<tr class="text-danger"><td colspan="3"><strong<i class="fa fa-info-circle" style="font-size:12pt;"></i> - No record found</td></tr>';
}
else{
foreach ($item_list as $row){
echo '<tr>';
echo '<td>'.$i++.'</td>';
echo '<td>'.$row->name.'</td>';
echo '<td>'.$row->price.'</td>';
echo '<td>'.$row->barcode.'</td>';
echo '</tr>';
}
}
echo'
</tbody>
But this shows me only one barcode on entire html body page which was generated by random number
I Want the final result something like this
Expected Result

// Create a folder in your root directory like : root/barcode
public function set_barcode($code){
//generate barcode
$file = Zend_Barcode::render('code128', 'image', array('text'=>$code), array());
$code = time().'1222';
imagepng($file,"barcode/{$code}.png");
$data['barcode'] = $code.'.png';
$this->load->view('dashboard/products',$data);
}
// Add view page like this
<img src="<?php echo base_url().'barcode/'.$barcode; ?>" alt="">

Related

Codeigniter 4 detect and differentiate homepage from other pages

I would like to differentiate my homepage with other pages as my structure is a little different from other pages but I have no clue is it to make use of public function view(). Currently I am working on 1 page which is my profile page, the link is localhost/account/profile, in this case, how do I differentiate homepage and account page? Below are my codes :
HTML
<header>
<nav></nav>
// only show slider if it's homepage
<slider></slider>
</header>
Controller
class Account extends BaseController
{
public function index()
{
echo view('templates/header');
echo view('account/profile');
echo view('templates/footer');
}
public function login()
{
echo view('templates/header');
echo view('account/login');
echo view('templates/footer');
}
public function register()
{
echo view('templates/header');
echo view('account/register');
echo view('templates/footer');
}
//--------------------------------------------------------------------
}
Routes
$routes->match(['get', 'post'], 'account/register', 'Account::register');
$routes->match(['get', 'post'], 'account/login', 'Account::login');
$routes->match(['get', 'post'], 'account/profile', 'Account::index');
Please let me know if the information I needed is insufficient. Thanks in advance guys.
Hmm... Somehow it's working using this method for me. Not sure whether this is a good way though.
<?php
$uri = service('uri');
if($uri->getSegment(1) == ''):
?>
<slider></slider>
<?php endif; ?>

Displaying Container Part Items From Content Picker Field

I have a content type called DayTile which I have setup with a content picker field that is limited to HotelSection type. This type is a container for the Hotels type.
I want to render all the hotels in the HotelSection when the DayTile has that section picked. Is this possible?
From what I have tried so far, it does not seem that the HotelSection's contained items are accessible as a content picker field.
The selected content items are exposed by the ContentPickerFields ContentItems property (see Orchard.ContentPicker.Fields.ContentPickerField).
To access this from a DayTile content item, let's say from a Razor template named "Content-DayTile.cshtml", you would do it like so:
#{
dynamic contentItem = Model.ContentItem; // How to access the content item depends on the context. In this case, we're in a Content shape template.
// Assuming your picker field is named "HotelSections" and attached to your DayTile content type (which in reality means it's attached to an automatically created part called "DayTile").
var picker = contentItem.DayTile.HotelSections;
var hotelSectionContentItems = picker.ContentItems; // Typed as IEnumerable<ContentItem>.
}
<ul>
#foreach(var hotelSectionContentItem in hotelSectionContentItems)
{
// You can now either access individual parts and fields of each hotel section content item and render it, or you can choose to build a shape for each item and display that. Here are examples:
<li>#hotelSectionContentItem.TitlePart.Title</li>
// or:
// Build a content shape for the content item.
var hotelSectionContentShape = BuildDisplay(hotelSectionContentItem, "Summary");
// Render the shape.
<li>#Display(hotelSectionContentShape)</li>
}
If I understand you correctly this should absolutely be possible.
You will want to override the Fields.ContentPicker view in your theme/module, and in the foreach loop instead of displaying a link to each HotelSection, you want to display that HotelSection content item, which in turn will display all the Hotels contained within the HotelSection, like so:
#using Orchard.ContentPicker.Fields
#using Orchard.Utility.Extensions;
#{
var field = (ContentPickerField) Model.ContentField;
string name = field.DisplayName;
var contentItems = field.ContentItems;
}
<p class="content-picker-field content-picker-field-#name.HtmlClassify()">
<span class="name">#name</span>
#if(contentItems.Any()) {
foreach(var contentItem in contentItems) {
#Display(contentItem.ContentManager.BuildDisplay(contentItem, "Detail"))
}
}
else {
<span class="value">#T("No content items.")</span>
}
</p>
If you are looking to access the Hotels directly from within the content picker field you will need to add a little bit more to the view, a little messy but like this:
#using Orchard.ContentPicker.Fields
#using Orchard.Utility.Extensions;
#{
var field = (ContentPickerField) Model.ContentField;
string name = field.DisplayName;
var contentItems = field.ContentItems;
}
<p class="content-picker-field content-picker-field-#name.HtmlClassify()">
<span class="name">#name</span>
#if(contentItems.Any()) {
foreach(var contentItem in contentItems) {
var container = contentItem.As<ContainerPart>();
if(container == null) {
continue;
}
var hotels = contentItem.ContentManager
.Query(VersionOptions.Published)
.Join<CommonPartRecord>().Where(x => x.Container.Id == container.Id)
.Join<ContainablePartRecord>().OrderByDescending(x => x.Position);
foreach(var hotel in hotels) {
// do something
}
}
}
else {
<span class="value">#T("No content items.")</span>
}
</p>
I'm missing some using statements at the top but the gist of it is there.

Prevent CakePHP from stripping chars from url passed as param?

I am developing an application using CakePHP 2.6 and having issues with passing a string containing url characters as a parameter through to a controller method.
In my view I have a chunk of code which echoes out a series of table rows containing data and passes through the page id, unit id and the id of the link which can sometimes contain a url.
<?php foreach($linklist as $l) { ?>
<tr id="Link_<?php echo $l['ID']; ?>">
<td><?php echo $l['Title']; ?></td>
<td class="buttontd"><?php echo $this->Form->postlink('Delete', array('action' => 'deletelink', $this->request->params['pass'][0], $results[0]['PageUnitTypeID'], $l['ID']), array('class' => 'button delete')); ?></td>
</tr>
<?php } ?>
When the postlink button passes the information over to the 'deletelink' action in the controller the url looks like this:
http://mydomainname.com/webpages/deletelink/239/7/urlhttp%3A%2F%2Fwww.google.co.uk%2F
Which shows that the url has been passed as the string but then in the action when I try to just var_dump() the third parameter it returns a string of www.google.co.uk and nothing more which is preventing me from doing a substr() call on the parameter to check if the first 3 characters are equal to url or not.
I have tried to wrap the parameter in the postlink call inside serialize() and urlencode() but neither has had the desired effect of returning the full string as
urlhttp%3A%2F%2Fwww.google.co.uk%2F
Does anyone know of a successful way to pass through a parameter like this without losing important characters?
Update 1: Deletelink action
public function deletelink($pid = null, $uid = null, $lid = null) {
$this->autoRender = false;
if (!is_null($pid) && is_numeric($pid) && !is_null($uid) && is_numeric($uid)) {
if (!is_null($lid)) {
if (substr($lid, 0, 3) == 'url') {
echo substr($lid, 0, 3);
} else {
echo substr($lid, 0, 3);
}
} else {
$this->Session->setFlash('It is unknown which link you wish to delete from the webpage', 'flash_message_bar', array('class' => 'error'));
return $this->redirect(array('action' => 'edit', $pid));
}
} else {
$this->Session->setFlash('It is unknown which on which webpage you wish to delete a link', 'flash_message_bar', array('class' => 'error'));
return $this->redirect(array('action' => 'index'));
}
}
CakePHP (or mod_rewrite I would say) is getting confused with the way your URL is formed.
Your safest option is to base64_encode the url parameter in the view, which will result in call similar to:
http://mydomainname.com/webpages/deletelink/239/7/dXJsaHR0cDovL3d3dy5nb29nbGUuY28udWsv
and base64_decode it later in the action, which will transform
dXJsaHR0cDovL3d3dy5nb29nbGUuY28udWsv
into
urlhttp://www.google.co.uk/

What is the proper way to do conditional formatting in a ZF2 MVC project?

In a ZF2 project I am developing, I would like to create a shell around the echo $this->content; statement in layout.phtml that would allow conditional formatting of the main content area. Specifically, I want to put the content into a column that is 75% wide and include some “ornamental” elements in a column that is 25% wide for most of the pages. However, I want to change to a single column for pages that need more space. My project is a CMS in which each page has an attribute that can tell either the view or the controller whether the page should be normal or wide. I have considered a number of methods for achieving what I’m after.
My “conditional formatting in the layout view” might look like this:
// module/Application/view/layout/layout.phtml:
//...
if ($templateNormal) {
echo "<div class='col-md-9'>";
} else {
echo "<div class='col-md-12'>";
}
echo $this->content;
if ($templateNormal) {
echo "</div>";
echo "<div class='col-md-3'>";
//... ornamentation
echo "</div>";
} else {
echo "</div>";
}
//...
While the above-method could work, for pure MVC I don’t think there is supposed to be any decision-making going on in the layout view.
My “conditional formatting in partial views” could look like this:
// module/Application/view/layout/layout.phtml:
//...
echo $this->partial('partial/open-shell.phtml');
echo $this->content;
echo $this->partial('partial/close-shell.phtml');
//...
// module/Application/view/partial/open-shell.phtml:
if ($templateNormal) {
echo "<div class='col-md-9'>";
} else {
echo "<div class='col-md-12'>";
}
// module/Application/view/partial/close-shell.phtml:
if ($templateNormal) {
echo "</div>";
echo "<div class='col-md-3'>";
//... ornamentation
echo "</div>";
} else {
echo "</div>";
}
Here the decision-making is taken out of the layout view, but it is simply put into other views so it's still in the view package and still not pure MVC.
In my “conditional formatting in the controller” solution, a pair of html script strings are developed in a controller function, and then passed on to the view. It might look like this:
// module/Application/view/layout/layout.phtml:
//...
echo $this->open-shell-script';
echo $this->content;
echo $this->close-shell-script';
//...
// some controller function:
//...
if ($templateNormal) {
$open-shell-script = "<div class='col-md-9'>";
$close-shell-script = "</div>";
$close-shell-script = "<div class='col-md-3'>";
$close-shell-script .= //... ornamentation
$close-shell-script .= "</div>";
} else {
$open-shell-script = "<div class='col-md-12'>";
$close-shell-script = "</div>";
}
//...
In this method, the decision-making is done in the controller where I assume it should be, but it seems odd to be writing html there.
Any comments or suggestions?
create two layout and in init() method of Module.php decide which layout should use .
public function init(ModuleManager $moduleManager) {
$sharedEvents = $moduleManager->getEventManager()->getSharedManager();
$sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
// This event will only be fired when an ActionController under the MyModule namespace is dispatched.
$controller = $e->getTarget();
$controller->layout(" your chose layout ");
}
}
There are many ways to accomplish this. This is one method and the logic lives in the controller:
controller
public function yourSampleAction()
{
// assign variables as usual to this view model
$viewModel = new ViewModel(array(
//vars
);
// this will be the "wrapper" and can be single, double column or anything else.
$wrapperViewModel = new ViewModel();
$wrapperViewModel->addChild($viewModel, 'innerContent');
// use this line when you want one column
$wrapperViewModel->setTemplate('path/to/your/single-column-wrapper.phtml');
// when this line you want two columns
$wrapperViewModel->setTemplate('path/to/your/two-column-wrapper.phtml');
return $wrapperViewModel;
}
two-column-wrapper.phtml
<div class='col-md-9'>
<?php echo $innerConntent; ?>
</div>
<div class='col-md-3'>
<!--- something else in here? -->
</div>
single-column-wrapper.phtml
<div class='col-md-12'>
<?php echo $innerConntent; ?>
</div>
Instead of setting different templates, you can adjust the Bootstrap Twitter classes by making the necessary classes dependent on a layout variable. You can use the logic in your controllers action to pass variables directly to the layout (not the view) like so:
$this->layout()->setVariables
(
array
(
'layoutVar1' => 75,
'someColClass' => ($someSwitch ? 'col-md-9':'col-md-12' ),
'layoutVar1' => 75,
)
);
and then just access these variables in the Layout as you would variables sent to the View. You don't have to even prepend them with "layout", they won't clash.

MODX - quip display extended field - photo using phpthumbof

Quip
phpthumbof
I have Quip running on my site and I am using a snippet to call a extended profile field from the author of the comment to display the user profile image.
SNIPPET
<?php
if (!empty($userid)) {
$user = $modx->getObject('modUserProfile', array('id' => $userid) );
$extendedfields = $user->get('extended');
$output = $extendedfields[$field];
}
if (isset($output)) { return $output;}
return $default;
In my Quip.comment TPL
<div class="quip-comment-right">
<img src="[[!quip_profile_image? &userid=`[[+author]]` &field=`nomination_file` &default=`text`]]" />
</div>
The above works perfectly and I can see the image, but I cant figure out how to add PHPthumbof, to change size etc....
$output = $modx->runSnippet('phpthumbof',array(
'input' => $output,
'options' => '&w=640&h=480&zc=0&aoe=0&far=0'
));

Resources