PKPASS not opennig in Passbook - passbook

I'm new to passbook. I created an web application using PHP-PKPass library to create passes for Passbook. I used the necessary licences. When I submit to create the form, it creates a pass, but the pass doesn't work on passbook. If I send it as email attachment, it shows null. It works fine on android. I'm on Windows PC so I can't use the iphone simulator to view logs. Here is a link to a pass created by me -
http://tanvir.tennisads.com/passbook/passes/pass-36252.pkpass
Can someone please help me identify what's wrong with the pass? Thanks in advance.
Update: I've removed the beacons and location part, but having the same issue. Here is the generated json code.
{
"description": "Kenedy Store",
"formatVersion": 1,
"organizationName": "Kenedy Store",
"passTypeIdentifier": "pass.com.retailness.testing.passbook",
"serialNumber": "449925",
"teamIdentifier": "NBN8H8W46L",
"coupon": {
"primaryFields": [
{
"key": "offer",
"label": "Any purchase",
"value": "25% off"
}
],
"auxiliaryFields": [
{
"key": "expires",
"label": "EXPIRES",
"value": "30-06-2015"
}
],
"backFields": [
{
"key": "terms",
"label": "TERMS AND CONDITIONS",
"value": "tos"
}
]
},
"backgroundColor": "rgb(255,255,255)",
"foregroundColor": "rgb(15, 15, 15)",
"labelColor": "rgb(85, 85, 85)",
"logoText": "Kenedy Store"
}
Here is the PHP code i used to create the pass...
<html>
<head>
<title>Passbook Demo</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles/bootstrap.min.css">
<link rel="stylesheet" href="styles/smoke.min.css">
<link rel="stylesheet" href="styles/custom.css">
<script src='scripts/jquery.min.js'></script>
<script src='scripts/bootstrap.min.js'></script>
<script src='scripts/smoke.min.js'></script>
</head>
<body>
<?php
function RandomString($length)
{
$characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
$randstring = '';
for ($i = 0; $i < $length; $i++) {
$randstring .= $characters[rand(0, strlen($characters))];
}
return $randstring;
}
$flag = false;
$name = urldecode($_POST['name']);
$amount = urldecode($_POST['amount']);
$message = urldecode($_POST['message']);
$expires = urldecode($_POST['expires']);
$email = urldecode($_POST['email']);
$uuid = urldecode($_POST['uuid']);
$major = urldecode($_POST['major']);
$minor = urldecode($_POST['minor']);
$tos = urldecode($_POST['tos']);
$appURL = urldecode($_POST['appURL']);
$lat = urldecode($_POST['lat']);
$lon = urldecode($_POST['lon']);
$beacon_msg = urldecode($_POST['beacon_msg']);
$location_msg = urldecode($_POST['location_msg']);
$target = "";
if($_FILES['file']['name']){
$flag = true;
$file = $_FILES['file'];
$n = $file['name'];
$ext = end((explode(".", $n)));
$target = "images/up/logo." .$ext;
move_uploaded_file($file['tmp_name'], $target);
}
require 'includes/PKPass/PKPass.php';
$pass = new PKPass\PKPass();
$pass->setCertificate('certificates/Certificate.p12');
$pass->setCertificatePassword('tanvir123');
$pass->setWWDRcertPath('certificates/AppleWWDRCA.pem');
$standardKeys = array(
'description' => "{$name}",
'formatVersion' => 1,
'organizationName' => "{$name}",
'passTypeIdentifier' => 'pass.com.retailness.testing.passbook', // 4. Set to yours
'serialNumber' => RandomString(6), //CHANGE IT TO RANDOMIZE
'teamIdentifier' => 'NBN8H8W46L'
);
$associatedAppKeys = array(
);
$relevanceKeys = array(
);
$styleKeys = array(
'coupon' => array(
'primaryFields' => array(
array(
'key' => 'offer',
'label' => "{$message}",
'value' => "{$amount}% off"
)
),
'auxiliaryFields' => array(
array(
'key' => 'expires',
'label' => 'EXPIRES',
'value' => "{$expires}"
)
),
'backFields' => array(
array(
'key' => 'terms',
'label' => 'TERMS AND CONDITIONS',
'value' => "{$tos}"
)
)
)
);
$visualAppearanceKeys = array(
'backgroundColor' => 'rgb(255,255,255)',
'foregroundColor' => 'rgb(15, 15, 15)',
'labelColor' => 'rgb(85, 85, 85)',
'logoText' => "{$name}"
);
$webServiceKeys = array();
// Merge all pass data and set JSON for $pass object
$passData = array_merge(
$standardKeys,
$associatedAppKeys,
$relevanceKeys,
$styleKeys,
$visualAppearanceKeys,
$webServiceKeys
);
$pass->setJSON(json_encode($passData));
// Add files to the PKPass package
$pass->addFile('images/icon.png');
$pass->addFile('images/icon#2x.png');
if($flag == false) $pass->addFile('images/logo.png');
else $pass->addFile($target);
$pass->addFile($target);
$data = $pass->create(true);
$path = 'passes/pass-'.RandomString(5).'.pkpass';
file_put_contents($path, $data);
//unlink($new_file_path);
$fullpath = 'http://' . $_SERVER['SERVER_NAME'] . '/passbook/' . $path;
?>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="col-md-2">
<img src="images/logo.png" height="93" width="156" alt="">
</div>
<div class="col-md-10 text-center">
<h2>Passbook / iBeacon Demo</h2>
</div>
</div>
</div>
<div class="col-md-6 col-md-offset-3 text-center">
Download the pass.<br>
Or use the QR Code instead: <br>
<?php
require 'includes/phpqrcode/qrlib.php';
QRCode::png($fullpath, $path . '.png');
?>
<img src="<?php echo $path . '.png'; ?>" width=500>
</div>
</div>
</body>
</html>
And here is the screenshot of what's hapenning when i try to download the pass from iphone: http://i.imgur.com/5NLAl3g.jpg

Looking at your pass.json I can see two errors.
"beacons": [{
"proximityUUID": "",
"relevantText": "",
"major": "0",
"minor": "0"
}],
"locations": [{
"longitude": "90.42607140943142",
"latitude": "23.7636902410487",
"relevantText": "office"
}],
The first error is that your beacons dictionary contains an invalid entry. You have not supplied a proximityUUID or relevantText.
The second error is being caught by Xcode.
Jun 10 09:09:02 pfr MobileSafari[4660] <Warning>: Invalid data error reading pass pass.com.retailness.testing.passbook/314548. Value for key 'latitude' must be of class NSNumber, but is actually of class __NSCFString.
You are providing your latitude and longitude values as strings when they need to be provided as decimals.
Drop the beacons array and the quotes around the lat and long values and you should be ok.
Update
Your new pass is fine. It is not loading on the phone because your web server is not applying a Content-Type header and therefore iOS does not recognise this file as a pass.
HTTP/1.1 200 OK
Date: Fri, 12 Jun 2015 17:25:58 GMT
Server: Apache
Last-Modified: Thu, 11 Jun 2015 07:44:56 GMT
Accept-Ranges: bytes
Content-Length: 20604
Add a Content-Type: application/vnd.apple.pkpass header to this file and you should find that it loads ok.
For more info on how to add the header, see the answers to this question.

Related

yii2 Dimensions to be validated and display the error message in the form

In yii2 project I have my own file structure setup. Anything uploaded will get saved as a file type. I can get the file dimensions using the file uploaded in the temp folder by yii2. Using those dimensions I set my own width and height and compare them. If the height and width is more than what I have declared It has display an error message in the form. Which I am unable to do it.
My Active Form
<div class="company-form">
<?php
$form = ActiveForm::begin([
'action'=>['company/logo', 'id'=>$model->company_id],
'validateOnSubmit' => true,
'options' =>
['enctype' => 'multipart/form-data','class' => 'disable-submit-buttons','id'=> 'companyLogoForm'],
'fieldConfig' => [
'template' => "<div class=\"row\">
<div class=\"col-xs-6 margin-top-8\">{label}</div>\n<div class=\"col-xs-6 text-right\">{hint}</div>
\n<div class=\"col-xs-12 \">{input}</div>
</div>",
],
]); ?>
<?= $form->errorSummary($model, $options = ['header'=>'','class'=>'pull-left']); ?>
<?= $form->field($model, 'company_name')->hiddenInput(['maxlength' => true])->label(false) ?>
<?= $form->field($file, 'file')->fileInput([])->label(Yii::t('app', 'Attach Logo'),['class'=> 'margin-top-8']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Save') : Yii::t('app', 'Save'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary','data' => ['disabled-text' => 'Please Wait']]) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
My Controller Action
public function actionLogo($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$file = new File;
$file->load(Yii::$app->request->post());
$a = UploadedFile::getInstance($file,'file');
$size = getimagesize($a->tempName);
$maxWidth = 500;
$maxHeight = 500;
if ($size[0] > $maxWidth || $size[1] > $maxHeight)
{
$model->addError('file', $error = 'Error Message');
if($model->hasErrors()){
return ActiveForm::validate($model);
}
}
$file->file = UploadedFile::getInstance($file,'file');
$file->file_name = $file->file->name;
$file->file_user = Yii::$app->user->id;
$file->file_type = 1;
if($file->save()){
$file->file_path = Files::getFilePath($file->file_id);
$validDir = $file->file->createFileDir($file->file_path, $file->file_id);
if($validDir){
$file->file->saveAs($file->file_path, false);
if($file->save()){
$model->company_file = $file->file_id;
$model->save();
return $this->redirect(['index']);
}
}
}
}
}
How do I add error message in the controller and pass that to display on my form on the modal box.
Note: my form is displayed on the modal box.
Thank you!!
You should handle the file processing in your model - or even better, create a specific UploadForm model for this purpose.
In that case you can use File Validation or a custom validator to set errors during model validation.
The built-in yii\validators\FileValidator gives you plenty pf validation rules out of the box.
This is actually pretty well explained in the documentation: Uploading Files
See also the documentation for FileValidator
Example for validating an uploaded image file:
namespace app\models;
use yii\base\Model;
use yii\web\UploadedFile;
class UploadForm extends Model
{
/**
* #var UploadedFile
*/
public $imageFile;
public function rules()
{
return [
[['imageFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg'],
];
}
public function upload()
{
if ($this->validate()) {
$this->imageFile->saveAs('uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
return true;
} else {
return false;
}
}
}
Try this validation rule
['imageFile', 'image', 'minWidth' => 250, 'maxWidth' => 250,'minHeight' => 250, 'maxHeight' => 250, 'extensions' => 'jpg, gif, png', 'maxSize' => 1024 * 1024 * 2],

Yii2: Images stored in different tables

Here my controller:
$model = new VehicleType();
if ($model->load(Yii::$app->request->post())) {
if($model->validate()){
$model->save();
$id = $model->id;
$model->file = UploadedFile::getInstance($model, 'file');
if($model->file){
$id = $model->id;
$imageName = "vehicletype_".$id.'_'.getdate()[0];
$model->file->saveAs('uploads/'.$imageName.'.'.$model->file->extension);
$station = VehicleType::findOne($id);
$station->image = '#web/uploads/'.$imageName.'.'.$model->file->extension;
$station->save();
}
return $this->redirect(['vehicletype/index']);
}
} else {
return $this->renderAjax('create', [
'model' => $model,
]);
}
}
My view:
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'station-form', 'options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'description')->textarea() ?>
<?= $form->field($model, 'file')->fileInput() ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
My model:
public function rules()
{
return [
[['description'], 'string'],
[['record_status'], 'integer'],
[['name', 'image'], 'string', 'max' => 255]
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Name',
'description' => 'Description',
'image' => 'Image',
'record_status' => 'Record Status',
];
}
/**
* #return \yii\db\ActiveQuery
*/
public function getVehicles()
{
return $this->hasMany(Vehicles::className(), ['vehicle_type_id' => 'id']);
}
}
With this I can upload only one picture/post, I want one post to have multiple pictures, so I create a new table call 'Image' to stored my pictures and have a one-to-many relationship.
But I run into a problem, how can I add data to 2 tables from just 1 form
I'm using Yii2 basic template
Thanks
Step 1
First create two variables in your vehicletype model.
public $uploadedImages;
public $imageforNewtable = array();
Step 2
Make sure to mention this imageforNewtable variable in your model rule.
[['imageforNewtable'], 'image', 'extensions' => 'png, jpg, JPEG'],
Step 3
In your form:
<?php $form = ActiveForm::begin(['id' => 'station-form', 'options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'imageforNewtable[]')->fileInput(['accept' => 'image/*']); ?>
Step 4
In Your Controller:
$model->uploadedImages = UploadedFile::getInstances($model,'imageforNewtable');
// Make sure to put "Instances" (plural of Instance) for uploading multiple images
$model->imageforNewtable = array(); // To avoid blank entries as we have entries in $_FILES not in $_POST.
foreach ($model->uploadedImages as $singleImage)
{
$model->imageforNewtable[] = time() . '_' . $singleImage->name;
}
Now bulk insert data in Images table :
$bulkInsertforimages = array(); //defined benchInsert array for images
$columnsArray = ['blog_id', 'image']; //Column names in which bulk insert will take place.
if ($model->imageforNewtable != '') {
foreach ($model->imageforNewtable as $singleData) {
$bulkInsertforimages[] = [
'blog_id' => $model->id,
'image' => $singleData,
];
}
}
if (count($bulkInsertforimages) > 0) {
$command = \Yii::$app->db->createCommand();
$command->batchInsert('YOUR_IMAGE_TABLE', $columnsArray, $bulkInsertforimages)->execute();
}

Drupal 7 - Keep me logged in and customizing the error messages

Can anybody help me in implementing Drupal 7 'Keep me logged in' feature and customize the error messages in login form.
In page--front.tpl.php i used <?php print front_login();?> for the login form and front_login() function is in template.php.
template.php functions are
<?php
function front_login() {
global $user;
if ($user->uid == 0) {
$form = drupal_get_form('front_login_form');
return theme('status_messages').render($form);
} else {
return '<div id="loginbar">' . t('Welcome back ') . ucwords($user->name) . '</div>';
}
}
function front_login_form($form, &$form_state) {
global $base_url;
$form['#id'] = 'login';
$haveAccount = '<div class="title"><span>Already have an account?</span><br>Log In Here</div>';
$forgot = '<div class="forgot">Forgot your password?</div>';
$form['#validate'] = user_login_default_validators();
$form['#submit'][] = 'front_login_form_submit';
$form['name'] = array(
'#type' => 'textfield',
'#id' => 'user_login',
'#prefix' => $haveAccount . '<div class="inputholder"><div class="icon glyphicon glyphicon-user"></div>',
'#suffix' => '</div>',
'#required' => TRUE,
'#attributes' => array('class' => array('footerinput'), 'placeholder' => array(t('Username'))),
);
$form['pass'] = array(
'#type' => 'password',
'#id' => 'pwd_login',
'#prefix' => '<div class="inputholder"><div class="icon"><img src="' . $base_url . '/' . drupal_get_path('theme', 'foodnet') . '/images/icon-2.png"></div>',
'#suffix' => "</div>",
'#required' => TRUE,
'#attributes' => array('class' => array('footerinput'), 'placeholder' => array(t('Password'))),
);
$form['keep_logged'] = array(
'#type' => 'checkbox',
'#title' => t('Keep me logged in'),
'#default_value' => 1,
'#prefix' => '<div class="row">
<div class="col-md-6">
<div class="checkbox"><label>',
'#suffix' => '</label></div>
</div>'
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#id' => 'but_login',
'#name' => 'but_login',
'#value' => t('Log In »'),
'#prefix' => '<div class="col-md-6"><div class="loginBtn">',
'#suffix' => '</div></div> </div>' . $forgot
);
$form['actions']['submit']['#attributes']['class'][] = 'btn';
$form['actions']['submit']['#attributes']['class'][] = 'btn-yellow';
$form['actions']['submit']['#attributes']['class'][] = 'btn-lg';
$form['actions']['submit']['#attributes']['class'][] = 'col-md-12';
return $form;
}
function front_login_form_submit($form, &$form_state) {
global $user;
$user = user_load($form_state['uid']);
$form_state['redirect'] = 'profile';
user_login_finalize($form_state);
if($form_state['values']['keep_logged'] ==0){
ini_set('session.cookie_lifetime', 0);
foreach ($_COOKIE as $key => $value) {
setcookie($key, $value, 0);
}
setcookie('_fnet_keepLogged', 0, time()+200000);
}else{
ini_set('session.cookie_lifetime', 2000000);
setcookie('_fnet_keepLogged', 1, time()+200000);
}
}
The login functionality works fine but I cannot customize the error messages. I have to set the errors inside the form. Please help.
When user click the 'Keep me logged in' checkbox I set '_fnet_keepLogged' cookie to 1, else to 0. I know that the default expiration of cookie in drupal is 23 days. I need to change that according to the value of '_fnet_keepLogged' cookie. Please help for this.
Thanks in advance.

Setting default values to a form on codeigniter

Sorry dudes, this is my first question, i've been dwelling your site for a little while and learnt a lot, but now i have a problem myself that couldn't find an answer, the thing is that i have a form that's filled in two diferent views, one to select a course that will be edited on the second one, the second one should have all the fields already filled with those that equals them on the database, i know that setting default values should be done using the set_value function defining a second parameter but it isn't working, everything else seems fine...
THIS IS MY FIRST VIEW
<?php echo link_tag('assets/css/nuevocurso.css');?>
<div id="infoMessage"><?php echo $message ?></div>
<section class="container">
<div class="register">
<h1>Ingrese el código del curso que desea modificar.</h1>
<?php echo form_open("curso/modificarcurso");?>
<p> <i>Código</i> <br /> <?php echo form_input($codigo);?> </p>
<p class="submit"><?php echo form_submit('commit', "Registrarse");?></p>
<?php echo form_close();?>
</div>
</section>
<br/>
THIS IS MY SECOND VIEW
<?php echo link_tag('assets/css/nuevocurso.css');?>
<div id="infoMessage"><?php echo $message ?></div>
<section class="container">
<div class="register">
<h1>Modifique los atributos de curso que desee.</h1>
<?php echo form_open("curso/gestionarcurso");?>
<p> <i>Nombre</i> <br /> <?php echo form_input($nombre);?> </p>
<p> <i>Descripcion</i> <br /> <?php echo form_textarea($descripcion);?> </p>
<p> <i>Codigo</i> <br /> <?php echo form_input($codigo);?> </p>
<p> <i>Alias</i> <br /> <?php echo form_input($alias);?> </p>
<p> <i>Programa</i> <br /> <?php echo form_textarea($programa);?> </p>
<p class="submit"><?php echo form_submit('commit', "Registrarse");?></p>
<?php echo form_close();?>
</div>
</section>
<br/>
AND THIS MY CONTROLLER
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Modificarcurso extends CI_Controller
{
public function index()
{
$this->load->database();
$this->load->library('ion_auth');
$this->load->model('nuevocurso_model');
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('codigo', 'Código', 'required|xss_clean');
$user = $this->ion_auth->user()->row();
if ($this->form_validation->run() == true)
{
$codigo = $this->input->post('codigo');
echo $codigo;
$flag = $this->db->query("SELECT codigo FROM curso WHERE codigo = '".$codigo."'");
$flag = $flag->result_array();
var_dump($flag);
if ($user->es_admin == 1 && !empty($flag))
{
echo "chupala maraco";
$this->data['codigo']= $codigo;
$this->data['tipo'] = "admin";
$this->manage($this->data);
}
$flag = $this->db->query("SELECT codigo FROM dicta_curso_profesor WHERE rut = '".$user->rut."' AND codigo = '".$codigo."'");
$flag = $flag->result_array();
if ((!empty($flag))&&($user->es_admin!=1)&&($user->es_profesor==1))
{
$this->data['codigo'] = $codigo;
$this->data['tipo'] = "profesor";
$this->manage($this->data);
}
if ($this->db->affected_rows()>0)
{
$this->data['message'] = 'EEEEEXITO';
}
else
{
$this->data['message'] = 'HAHAHAHAHA';
}
}
$this->data['codigo'] = array(
'name' => 'codigo',
'id' => 'codigo',
'type' => 'text',
'value' => $this->form_validation->set_value('codigo'));
echo $user->es_admin;
echo $user->es_profesor;
$this->load->view('home/header_view');
$this->load->view('curso/gestionarcursoredirect',$this->data);
$this->load->view('home/footer_view');
}
public function manage($datos)
{
$this->load->database();
$this->load->helper('html');
$this->load->helper('form');
$this->load->library('form_validation');
$user = $this->ion_auth->user();
$this->form_validation->set_rules('nombre','Nombre','required|xss_clean');
$this->form_validation->set_rules('alias','Alias','required|xss_clean');
$this->form_validation->set_rules('codigo','Codigo','required|xss_clean');
$this->form_validation->set_rules('descripcion','Codigo','required|xss_clean');
if ($this->form_validation->run() == true)
{
$nombre = $this->input->post('nombre');
$alias = $this->input->post('alias');
$descripcion = $this->input->post('descripcion');
$codigo = $this->input->post('codigo');
$rutprofesor = $this->input->post('profesor');
$flag = $this->db->query("SELECT nombre, codigo FROM curso WHERE curso.nombre = '".$nombre."' OR curso.codigo = '".$codigo."'");
$flag = $flag->result_array();
if (empty($flag))
{
$query = $this->db->query("INSERT INTO curso (nombre, alias, codigo, descripcion) VALUES ('".$nombre."','".$alias."','".$codigo."','".$descripcion."')");
$query = $this->db->query("INSERT INTO dicta_curso_profesor (rut, codigo) VALUES ('".$rutprofesor."','".$codigo."')");
}
if ($this->db->affected_rows()>0)
{
$this->data['message'] = 'EEEEEXITO';
}
else
{
$this->data['message'] = 'HAHAHAHAHA';
}
}
$codigo = $this->input->post('codigo');
$curso = $this->db->query("SELECT * FROM curso WHERE curso.codigo = '".$codigo."'");
$curso = $curso->result_array();
var_dump($curso);
echo $curso[0]['nombre'];
$this->data['nombre'] = array(
'name' => 'nombre',
'id' => 'nombre',
'type' => 'text',
'value' => $this->form_validation->set_value('nombre', $curso[0]["nombre"]),
);
$this->data['descripcion'] = array(
'name' => 'descripcion',
'id' => 'descripcion',
'type' => 'text',
'value' => $this->form_validation->set_value('descripcion', $curso[0]['descripcion']),
'maxlength' => '300',
'rows' => '5',
'cols' => '35',
);
$this->data['codigo'] = array(
'name' => 'codigo',
'id' => 'codigo',
'type' => 'text',
'value' => $this->form_validation->set_value('codigo', $curso[0]['codigo']),
'maxlength' => '8',
);
$this->data['programa'] = array(
'name' => 'programa',
'id' => 'programa',
'type' => 'text',
'value' => $this->form_validation->set_value('programa', $curso[0]["programa"]),
);
$this->data['alias'] = array(
'name' => 'alias',
'id' => 'alias',
'type' => 'text',
'value'=> $this->form_validation->set_value('alias', $curso[0]["alias"]),
'maxlength' => '14',
);
$this->data['profesores'] = $this->nuevocurso_model->get_profesores();
$this->load->view('home/header_view');
$this->load->view('curso/gestionarcurso',$this->data);
$this->load->view('home/footer_view');
}
}
the set_value are in the last function called manage on the controller, those are not working, don't worry about the model, i'm not yet using the only function stored in it.
Thank you, people, stackoverflow is amazing!
The CodeIgniter form helper expects two arguments if you want to set the value, example:
echo form_input('nombre', $nombre);
As the manual says: "You can minimally pass the field name and value in the first and second parameter"
http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
Will it work in your view like this:
echo form_input(array('name' => 'codigo', 'id' => 'codigo'), set_value('codigo', 'YOUR_VALUE'));

Forcing print page break after X records using CGridView

I use CGridView to render a result (invoice rows) from a db query. This is done inside a <div> on html page that is later converted to a PDF using wkhtmltopdf and printed. The problem is that today I have no support for page break so if number of invoice rows are greater than 10 the remaining rows are not visible. I can't let the div flow since I have an invoice footer with an absolute position that can't move.
Is there a way to force a page break and continue rendering rows on a separate page?
Below is part of the CGridView code used.
<...plenty of html---->
<div class="invoiceRow">
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dpRows,
'cssFile' => Yii::app()->request->baseUrl . '/css/invoice.css',
'summaryText' => '',
'enablePagination' => false,
'columns' => array(
'number',
'name',
'description',
'amount',
array (
'name'=>'value',
'header' => 'netprice',
'value' => 'number_format($data->value,2,","," ")'
),
));
?>
</div>
<---more html ----->
If wkhtml is able to parse css (it seems so) you could try:
<div style="page-break-after:always">
//X invoices here
</div>
if(!empty($model))
{
if($model->content_type==1)
{
$sentences = explode ('<div style="page-break-after: always;"><span style="display:none"> </span></div>',$model->content);
?>
<div id="datashow">
<?php
echo $sentences[0];
?>
</div>
<?php
$dummy=array();
$kcnt=preg_match_all('/page-break-after: always/', $model->content,$dummy);
// echo $model->content;
}
<script>
$("#pagebreakdiv").find(":button").click(function () {
var datashow=$('#datashow');
var a=this.value;
var bid='<?php echo $bid; ?>';
var id='<?php echo $id; ?>';
var pdata = {};
pdata["bitt"] = a;
pdata["bid"] = bid;
pdata["id"] = id;
$.ajax(
{
url : "<?php echo Yii::app()->request->baseUrl; ?>/UserSimple/Contentpagebreak",
type: "POST",
data : pdata,
success:function(data, textStatus, jqXHR)
{
datashow.html(data);
},
error: function(jqXHR, textStatus, errorThrown)
{
}
});
});
</script>