I have values in a database for example: 830,400,000 and in the view I want to display it as $830.4
In the view I thought to use the pattern option but I was unclear how to use it:
<td class="nonBulletList">
<?= $this->Number
->currency($currentExpenses,
'USD',
['places' => 1],
['pattern' => '###.#']) ?>
</td>
Related
from this html code I have to extract two values, two separate fields: the first in 'name' and the second in 'value'
<table>
<tbody>
<tr>
<td>
<span><strong>CPU & Dissipatore </strong></span>
</td>
<td>
<span>Intel i7-11700K Dissipatore a Liquido 240mm </span>
</td>
</tr>
</table>
Xpath code:
array(
'name' => ".//table//tr//td[1]",
'value' => ".//table//tr//td[2]",
),
So I get nothing. What am I doing wrong?
Like this:
//tr//td/span
Output
CPU & Dissipatore
Intel i7-11700K Dissipatore a Liquido 240mm
Name/value pairs in XPath (3.1) would be maps not arrays so in XPath 3.1 you can use e.g.
map {
'name' : //table//tr//td[1]/string(),
'value' : //table//tr//td[2]/string()
}
Online sample.
this is my simple registration. I want to send an email to the user's after submitting button in this registration form.How can i do that??Thanx in advance.
1. In the view i have made an simple registration form as u can see i have added some basic information.
2.In my controller i have added validations. And save them in database.
4.And model has simple insert query.
form_view.php
<table>
<tr>
<td>Name</td><td><?php echo form_input($name);?></td>
<td><?php echo form_error('name');?></td>
</tr>
<tr>
<td>Email</td><td><?php echo form_input($email);?></td>
<td><?php echo form_error('email');?></td>
</tr>
<tr>
<td>Phone</td><td><?php echo form_input($phone);?></td>
<td><?php echo form_error('phone');?></td>
</tr>
<tr>
<td>Address</td><td><?php echo form_input($address);?></td>
<td><?php echo form_error('address');?></td>
</tr>
<tr>
<td>Division</td><td><?php echo form_dropdown('division',$division,'Please Select');?></td>
</tr>
<td></td><td><?php echo form_submit($submit);?></td>
</tr>
</table>
main.php
<?php
class main extends CI_Controller{
public function viewForm(){
$this->load->view('form_view');
}
public function insertData(){
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Full Name', 'required|min_length[5]|max_length[12]|is_unique[address.name]');
$this->form_validation->set_rules('phone', 'Contact field', 'required|min_length[5]|max_length[12]|is_unique[address.phone]');
$this->form_validation->set_rules('address', 'Full Address', 'required|min_length[5]|max_length[12]|is_unique[address.address]');
$this->form_validation->set_rules('email', 'Email Address', 'required|min_length[5]|max_length[12]|is_unique[address.email]');
if($this->form_validation->run()==FALSE){
$this->load->view('form_view');
}else{
$sql="Select MAX(id) from address";// Auto Increment
$query= mysql_query($sql);
$selectid= mysql_fetch_array($query);
$finalid=$selectid[0]+1;
$data=array();
$data['id']=$finalid;
$data=array();
$data['name']=$this->input->post('std_name');
$data['phone']=$this->input->post('std_phone');
$data['address']=$this->input->post('std_address');
$data['division']=$this->input->post('division');
$data['email']=$this->input->post('email');
$this->load->model('main_model');
$this->main_model->save_user($data);
redirect('main/viewForm');
}
}
main_model.php
<?php
class main_model extends CI_Model{
public function save_user($data){
$this->db->insert('address',$data);
}
?>
}
?>
You might want to consider adding two columns on you user info table. Something like varchar activation_code & tinyint activated. On save user info generate activation code and send user a mail with that code within a link of your application url as well as save that code for that specific user with activated false value. On verify that code using that link change activated to true.
That will be my approach.
Before we start, I just want to point out that you should not have queries in your controller. That part must be in a model.
To send an email, you can use the codeigniter's library :
https://ellislab.com/codeigniter/user-guide/libraries/email.html
Here's how you can use it in your case :
if($this->form_validation->run()==FALSE)
{
$this->load->view('form_view');
}
else
{
$email = $this->input->post('email');
//Your stuff before the redirect
//If you have any particular smtp configuration (here, gmail)
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_user' => 'myemail#gmail.com',
'smtp_pass' => 'mypassword',
'smtp_port' => '465',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->from('MyName#MySite.com', 'MyName');
$this->email->to($email);
$this->email->subject('Mail subject');
$msg = "Welcome to my website !";
$this->email->message($msg);
if($this->email->send())
{
//Stuff if mail succeded
}
else
{
//Stuff if mail failed
}
redirect('main/viewForm');
}
Hi i have one table in my database which has list of states and i want to fetch this data from the table but my query is not executing properly it gives me some error
<?php
require_once('../Config/database.php');
$result1=$this->Signup->query("SELECT * FROM states");
//echo $popular;
while($post = mysql_fetch_array($result1))
{ ?>
<table width="380">
<tr>
<td class="table_txt"><a class="thickbox tn" href="demo.php?state_name=<?php echo $post['state_name']?>&state_id=<?php echo $post['state_id']?>&height=430&height=430&width=700&inlineId=myOnPageContent"><?php echo $post['state_name']?></a></td>
</tr>
</table>
<?php }
?>
But it gives me error
Warning (512): Method SignupHelper::query does not exist [CORE\Cake\View\Helper.php, line 192
Warning (2): mysql_fetch_array() expects parameter 1 to be resource, null given
Please read the documentation first.
It seems you are trying to get the states, inside the View, with a query.
You need to separate the view from the model.
Create a State model.
Use something like this in your controller:
$this->loadModel('State');
$states = $this->State->find('list'); // this will create a key => value array with the IDs and names
$this->set('states', $states);
In your view, use
<table width="380">
<tr>
<?php foreach ($states as $stateId => $stateName) {
<td class="table_txt"><a class="thickbox tn" href="demo.php?state_name=<?php echo $stateName?>&state_id=<?php echo $stateId?>&height=430&height=430&width=700&inlineId=myOnPageContent"><?php echo $stateName ?>></a></td>
<?php } ?>
</tr>
You might still need some changes, but this is the main idea.
I'm having some trouble with my site. What I want this view to do is display all invoices that relates to a userid(in another table), Instead the code is printing out all the invoices in the one view(disregarding the user id). When looking at the sql statement that cakephp debug spits out it shows the where as a blank(don't worry I'll include the actual sql statment). I also have session code created but I am unsure how to code it so that the mysql data will say where userid = current user;
here is the code for the view
<table width="100%" border="1">
<table width="100%" border="1">
<tr>
<th>Biller</th>
<th>Subject</th>
<th>Date</th>
<th>Action</th>
</tr>
<?php foreach($invoices as $invoice):?>
<tr> debug($invoices);
<td align='center'><?php echo $this->Html->link($invoice['Invoice']['biller'],
array('action' => 'viewinvoice', $invoice['Invoice']['id'])); ;?> </td>
<td align='center'><?php echo $invoice['Invoice']['subject']; ?></td>
<td align='center'><?php echo $invoice['Invoice']['datecreated']; ?></td>
<td align='center'><button>View Invoice</button><button>Dispute Invoice</button></td>
</tr>
<?php endforeach; ?>
</table>
here is the code in the class relating to this view
public function payinvoice($id = null){
$this->set('title_for_layout', 'Pay Invoice');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.jpg');
$this->layout='home_layout';
$this->set('invoices', $this->Invoice->find('all' , array('conditions' => array('Invoice.biller' => $id))));
}
and here is the sql code that site is using to retrieve the data
SELECT `Invoice`.`id`, `Invoice`.`to`, `Invoice`.`biller`, `Invoice`.`subject`, `Invoice`.`description`, `Invoice`.`amount`, `Invoice`.`datecreated`, `Invoice`.`duedate` FROM `pra_cake`.`invoices` AS `Invoice` WHERE `Invoice`.`biller` IS NULL
It looks like you are not passing an id into your page. The url should look like:
/invoices/payinvoice/2
This is probably the issue of the url
try this
<?php echo $this->Html->link('Invoice',
array('controller' => 'invoices',
'action' => 'payinvoice',
$invoice['Invoice']['id'])
);?>
it will generate
Invoice
I am following Steven Sanderson's blog post here to create an editable and variable length list of items. In his post he uses divs to display a new item in the list but I am using a table. Thus, my partial view for each item is rendering a tr tag with the various fields to edit. Right now my partial view looks something like this:
<tr>
#using (Html.BeginCollectionItem("LineItems"))
{
<td>
#Html.TextBoxFor(m => m.Description)
#Html.ValidationMessageFor(m => m.Description)
</td>
<td>
#Html.TextBoxFor(m => m.Quantity)
#Html.ValidationMessageFor(m => m.Quantity)
</td>
<td>
#Html.TextBoxFor(m => m.Amount)
#Html.ValidationMessageFor(m => m.Amount)
</td>
}
</tr>
This actually renders correctly on all browsers I have tested but the problem is that this really generates invalid HTML as it places a hidden input tag right after the opening tr tag.
<tr>
<input type="hidden" name="LineItems.index" .... />
<td>
...
</td>
...
</tr>
There is a comment by another user on the linked post that says you can move the using statement into the first tag and it works but I haven't been able to get this to work using ASP.NET MVC 3 and the Razor view engine.
Does anyone have any idea how to use the logic presented by Steven Sanderson but get the hidden index input field inside the first td so as not to generate invalid HTML?
Thanks
After a bit of experimenting I came up with:
<tr>
<td>
#using (Html.BeginCollectionItem("LineItems"))
{
#Html.TextBoxFor(m => m.Description)
#Html.ValidationMessageFor(m => m.Description)
#:</td>
#:<td>
#Html.TextBoxFor(m => m.Quantity)
#Html.ValidationMessageFor(m => m.Quantity)
#:</td>
#:<td>
#Html.TextBoxFor(m => m.Amount)
#Html.ValidationMessageFor(m => m.Amount)
}
</td>
</tr>
that did the trick for me.