Hi, I have problem with routes, it's always return "Missing Required Parameters".Please see my code below. Thank you! I think my route is wrong, what should I do?
//Controller Code
public function index($id = 0,$dateStart = null, $dateEnd = null)
{
//$current_date = date('Y-m-d');
// $attendances= Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')-
>where('Date','=',$current_date)->get();
// return view('attendance.index',compact('attendances'))
if($id == 0 && $dateStart == null && $dateEnd == null)
{
$current_date = date('Y-m-d');
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')-
>where('Date','=',$current_date)->get();
return view('manage.index',compact('attendances'));
}
elseif ($id != 0)
{
$sUser = User::select('name')->where('id','=',$id)->get();
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')->where('user_id','=',$id)-
>get();
return view('manage.index',compact('attendances','sUser'));
}
elseif($dateStart != null && $dateEnd == null)
{
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')
>whereBetween('Date',$dateStart,$dateEnd)->get();
return view('manage.index',compact('attendances'));
}
// return view('manage.index');
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
}
And here is my route.
Route::get('manageattendance/{id}/{dateStart}/{dateEnd}',
[App\Http\Controllers\ManageAttendanceController::class, 'index'])->name('manageattendance');
if you set the parameters in function must say for route these parameters are not required are optionally add ? after each parameter
Route::get('manageattendance/{id?}/{dateStart?}/{dateEnd?}',
Related
Argument 1 passed to PhpOffice\Common\Drawing::pixelsToEmu() must be of the type float, null given, C:\xampp\htdocs\vendor\phpoffice\phppresentation\src\PhpPresentation\Writer\PowerPoint2007\Abstra...
class GeneratePPT extends Controller{
//generateppt
public function generateppt($id){
if(Auth::user()->user_roles == 'superadmin'
|| Auth::user()->user_roles == 'admin'
|| Auth::user()->user_roles == 'officer'){
// do nothing and pass to process
}
else{
return redirect('/')->withError("You don't have permission to download");
}
//convert encrypted id to actutal decrypt value
//get id from route parameter
$id = request()->route('id');
$contracts_id = Crypt::decryptString($id);
$user = ContractDocument::where("contracts_id",$contracts_id)->first();
$contracts = Contract::where("id",$contracts_id)->first();
$shop_branches_id = $contracts->shop_branches_id;
$shop_branches = ShopBranch::where("id",$shop_branches_id)->first();
$family_members = FamilyMember::where("contracts_id",$contracts_id)->get();
// delete old file
if(Storage::exists("public/temp/{$contracts->apply_user_name}.ppt")){
Storage::delete("public/temp/{$contracts->apply_user_name}.ppt");
}
//photo from ContractDocument
$loan_user_photo = $user->loan_user_photo;
$objPHPPresentation = new PhpPresentation();
$layout = $objPHPPresentation->getLayout();
$layout->setCX(8.5, $layout::UNIT_INCH);
$layout->setCY(14, $layout::UNIT_INCH);
//create first table
$currentSlide = $objPHPPresentation->getActiveSlide();
self::createtitle($currentSlide);
self::createfirstTable($currentSlide,9,$contracts,$shop_branches,$family_members,$loan_user_signature,$witness_signature);
// Create user
if ($loan_user_photo != null) {
$currentSlide = $objPHPPresentation->createSlide();
self::createslide($loan_user_photo,$currentSlide,"Borrower ဓါတ်ပုံ");
}
$oWriterPPTX = IOFactory::createWriter($objPHPPresentation, 'PowerPoint2007');
$savepath = Storage::path("Loan/contract_{$contracts_id}");
$oWriterPPTX->save($savepath. "/contract_{$contracts_id}.ppt");
//update data in daatabase
ContractDocument::where('contracts_id', $contracts_id)->update(["final_all_combined_ppt_contract"=> "Loan/contract_{$contracts_id}/contract_{$contracts_id}.ppt"]);
//move and allow download
Storage::copy("Loan/contract_{$contracts_id}/contract_{$contracts_id}.ppt", "public/temp/{$contracts->apply_user_name}.ppt");
//Storage::download("public/temp/contract_{$contracts_id}.ppt","contract_{$contracts_id}.ppt");
$myFile = storage_path("app/public/temp/{$contracts->apply_user_name}.ppt");
return response()->download($myFile)->deleteFileAfterSend(true);
}
The orignial code was like this , I want to get landline_no value also in getRecords, How to do that
public function checklead() {
$lead = $_POST['number'];
$check = $this->common_model->getRecords('leads',array("phone_no"=>$lead));
if(count($check) > 0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$lead));
if($lead->assignto_self != 0) {
$assignto = $lead->assignto_self;
$key = 'Self Assign';
} else if($lead->assignto_se != 0) {
$assignto = $lead->assignto_se;
$key = '';}
What I have achieved so far,but not getting array values from getRecords
$lead = $_POST['number'];
$check = $this->common_model->getRecords('leads',array("phone_no"=>$lead),array("landline_no"=>$lead));
//echo "<pre>";
//print_r($check);
//echo $check[0]['landline_no'];exit;
if(count($check) > 0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$lead,"landline_no"=>$check[0]['landline_no']));
Code for getRecords:
function getRecords($table,$db = array(),$select = "*",$ordercol = '',$group = '',$start='',$limit=''){
$this->db->select($select);
if(!empty($ordercol)){
$this->db->order_by($ordercol);
}
if($limit != '' && $start !=''){
$this->db->limit($limit,$start);
}
if($group != ''){
$this->db->group_by($group);
}
$q=$this->db->get_where($table, $db);
return $q->result_array();
}
// Get Recored row
public function getRecored_row($table,$where)
{
$q = $this->db->where($where)
->select('*')
->get($table);
return $q->row();
}
Check my answer: This code also working well, i have written, but i am not sure , this logic is correct or not kindly check this one.
public function checklead() {
$lead = $_POST['number'];
if($this->common_model->getRecords('leads',array("phone_no"=>$lead)))
{
$check=$this->common_model->getRecords('leads',array("phone_no"=>$lead));
}
else
{
$check=$this->common_model->getRecords('leads',array("landline_no"=>$lead));
}
echo "<pre>";
//echo $check;
//print_r($check); exit;
$p= $check[0]['phone_no'];
$l= $check[0]['landline_no'];
// exit;
if(count($p) > 0 || count($l)>0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$p));
$lead1 = $this->common_model->getRecored_row('leads',array("landline_no"=>$l));
if($lead->assignto_self != 0 || $lead1->assignto_self != 0) {
$assignto = $lead->assignto_self;
$key = 'Self Assign';
} else if($lead->assignto_se != 0 || $lead1->assignto_se != 0) {
$assignto = $lead->assignto_se;
$key = '';
}else if($lead->assignto_tl != 0 || $lead1->assignto_tl != 0) {
$assignto = $lead->assignto_tl;
$key = '';
} else if($lead->uploaded_by != 0 || $lead1->uploaded_by != 0) {
$assignto = $lead->uploaded_by;
$key = 'Uploaded by';
}
$user = $this->common_model->getRecored_row('admin',array("id"=>$assignto));
$role = $this->common_model->getRecored_row('role',array("id"=>$user->role));
$this->session->set_flashdata('message', array('message' => 'This Lead Already exist with '.$user->name.' ('.$role->role.') '.' ','class' => 'danger'));
redirect(base_url().'leads');
} else {
redirect(base_url().'leads/add_newlead/'.$lead);
}
}
There does not seem to be any reason to use getRecords(). The $check value has no useful purpose and creating it is a waste of resources.
We don't need $check because getRecord_row() will return the "lead" if found so the only check needed is to see if getRecord_row() returns anything. getRecord_row() uses the database function row() which returns only one row or null if no rows are found. Read about row() here.
If what you want is to find the "lead" that has either a "phone_no" or a "landline_no" equal to $_POST['number'] then you need to use a custom string for the where clause. (See #4 at on this documentation page.) You need a custom string because getRecord_row() does not allow any other way to ask for rows where a='foo' OR b='foo'. Here is what I think you are looking for.
public function checklead()
{
// use input->post() it is the safe way to get data from $_POST
$phone = $this->input->post('number');
// $phone could be null if $_POST['number'] is not set
if($phone)
{
$lead = $this->common_model->getRecored_row('leads', "phone_no = $phone OR landline_no = $phone");
// $lead could be null if nothing matches where condition
if($lead)
{
if($lead->assignto_self != 0)
{
$assignto = $lead->assignto_self;
$key = 'Self Assign';
}
else if($lead->assignto_se != 0)
{
$assignto = $lead->assignto_se;
$key = '';
}
}
}
}
The main difference between getRecords() and getRecord_row() is the number of records (rows of data) to return. getRecord_row() will return a maximum of one record while getRecords() might return many records.
getRecords() accepts arguments that allow control of what data is selected ($db, $select), how it is arranged ($ordercol, $group), and the number of rows to retrieve ($limit) starting at row number x ($start) .
As soon an order is placed in magento, the order item has Item Status as 'Ordered'. I am able to fetch this status. But I need to edit this status,something like 'creating'.
Tried Using the code below but the changes are not reflected
$order = Mage::getModel("sales/order")->loadByIncrementId($orderId);
$ordered_items = $order->getAllVisibleItems();
foreach($ordered_items as $item){
$item->getStatus();
$item->setStatus('Creating');
$order->save();
}
Even tried with an option suggested here Howto update order item's custom option in Magento? which is also not working.
Please add your suggestions here. Thanks in advance
Order item don't have a separate field - status. To understand how to determine status you can see method Mage_Sales_Model_Order_Item :: getStatusId
/**
* Retrieve item status identifier
*
* #return int
*/
public function getStatusId()
{
$backordered = (float)$this->getQtyBackordered();
if (!$backordered && $this->getHasChildren()) {
$backordered = (float)$this->_getQtyChildrenBackordered();
}
$canceled = (float)$this->getQtyCanceled();
$invoiced = (float)$this->getQtyInvoiced();
$ordered = (float)$this->getQtyOrdered();
$refunded = (float)$this->getQtyRefunded();
$shipped = (float)$this->getQtyShipped();
$actuallyOrdered = $ordered - $canceled - $refunded;
if (!$invoiced && !$shipped && !$refunded && !$canceled && !$backordered) {
return self::STATUS_PENDING;
}
if ($shipped && $invoiced && ($actuallyOrdered == $shipped)) {
return self::STATUS_SHIPPED;
}
if ($invoiced && !$shipped && ($actuallyOrdered == $invoiced)) {
return self::STATUS_INVOICED;
}
if ($backordered && ($actuallyOrdered == $backordered) ) {
return self::STATUS_BACKORDERED;
}
if ($refunded && $ordered == $refunded) {
return self::STATUS_REFUNDED;
}
if ($canceled && $ordered == $canceled) {
return self::STATUS_CANCELED;
}
if (max($shipped, $invoiced) < $actuallyOrdered) {
return self::STATUS_PARTIAL;
}
return self::STATUS_MIXED;
}
and available statuses:
/**
* Retrieve order item statuses array
*
* #return array
*/
public static function getStatuses()
{
if (is_null(self::$_statuses)) {
self::$_statuses = array(
//self::STATUS_PENDING => Mage::helper('sales')->__('Pending'),
self::STATUS_PENDING => Mage::helper('sales')->__('Ordered'),
self::STATUS_SHIPPED => Mage::helper('sales')->__('Shipped'),
self::STATUS_INVOICED => Mage::helper('sales')->__('Invoiced'),
self::STATUS_BACKORDERED => Mage::helper('sales')->__('Backordered'),
self::STATUS_RETURNED => Mage::helper('sales')->__('Returned'),
self::STATUS_REFUNDED => Mage::helper('sales')->__('Refunded'),
self::STATUS_CANCELED => Mage::helper('sales')->__('Canceled'),
self::STATUS_PARTIAL => Mage::helper('sales')->__('Partial'),
self::STATUS_MIXED => Mage::helper('sales')->__('Mixed'),
);
}
return self::$_statuses;
}
I am working with magento and have a question in mind that why we use $this__("Some text") instead simple echo magento. can anyone ?
When you call
echo $this->__("some text");
You can start by looking at Mage_Core_Helper_Abstract
/**
* Translate
*
* #return string
*/
public function __()
{
$args = func_get_args();
$expr = new Mage_Core_Model_Translate_Expr(array_shift($args), $this->_getModuleName());
array_unshift($args, $expr);
return Mage::app()->getTranslator()->translate($args);
}
Next is Mage_Core_Model_App
/**
* Retrieve translate object
*
* #return Mage_Core_Model_Translate
*/
public function getTranslator()
{
if (!$this->_translator) {
$this->_translator = Mage::getSingleton('core/translate');
}
return $this->_translator;
}
Which is handed to Mage_Core_Model_Translate
/**
* Translate
*
* #param array $args
* #return string
*/
public function translate($args)
{
$text = array_shift($args);
if (is_string($text) && ''==$text
|| is_null($text)
|| is_bool($text) && false===$text
|| is_object($text) && ''==$text->getText()) {
return '';
}
if ($text instanceof Mage_Core_Model_Translate_Expr) {
$code = $text->getCode(self::SCOPE_SEPARATOR);
$module = $text->getModule();
$text = $text->getText();
$translated = $this->_getTranslatedString($text, $code);
}
else {
if (!empty($_REQUEST['theme'])) {
$module = 'frontend/default/'.$_REQUEST['theme'];
} else {
$module = 'frontend/default/default';
}
$code = $module.self::SCOPE_SEPARATOR.$text;
$translated = $this->_getTranslatedString($text, $code);
}
//array_unshift($args, $translated);
//$result = #call_user_func_array('sprintf', $args);
$result = #vsprintf($translated, $args);
if ($result === false) {
$result = $translated;
}
if ($this->_translateInline && $this->getTranslateInline()) {
if (strpos($result, '{{{')===false || strpos($result, '}}}')===false || strpos($result, '}}{{')===false) {
$result = '{{{'.$result.'}}{{'.$translated.'}}{{'.$text.'}}{{'.$module.'}}}';
}
}
return $result;
}
which returns the resulting text. This is a quick walkthrough of how everything would be handled, you should view the classes themselves to get a more in-depth understanding.
In simple when you call echo $this->__('some text') it look up same
text in CSV file which is located in
app>locale
or
app>design>frontend>YOUR_PACKAGE>YOUR_THEME_NAME>locale>translate.csv
file if the same word exist then it translate a word
means it is very useful in multi-language website
$this->__("Some text")
Used for translation purpose
I use Codeigniter's _remap function to remap all urls to www.website.com. This works for 99% of cases, but I'd like it to ignore certain URLS (specifically /admin,/contact,/submit,/top,/browse). These URLs have content I'd like to display.
How would I achieve this?
public function _remap($urlname)
{
if($urlname == "index") {
// If this is the index, redirect to the most recent startup
redirect("s/".$this->Startup_model->getMostRecent(), 'refresh');
} else {
// If they didn't go to the index, find the startup they were after
$id = $this->Startup_model->matchName($urlname);
// Check to see if the name they entered was a real startup, if not redirect to missing page
if($id == null) {
$data['urlname'] = $urlname;
$this->load->view('header/header');
$this->load->view('content/missing', $data);
$this->load->view('footer/footer');
} else {
// They got the name right! Load the page...
$data['values'] = $this->Startup_model->buildStartup($id);
// If there was no next startup avaiable, pass that info through
$next = $this->Startup_model->findNext($id);
if($next == null) {
$next = '343z61v';
}
// If there was no previous startup avaiable, pass that info through
$previous = $this->Startup_model->findPrevious($id);
if($previous == null) {
$previous = '343z61v';
}
$data['next'] = $next;
$data['previous'] = $previous;
$this->load->view('header/header');
$this->load->view('content/startup', $data);
$this->load->view('footer/footer');
}
}
}
Try this:
function _remap($urlname, $params = array())
{
if(is_callable(array($this, $urlname))){ //If the function exists, is called, if not using the usual
return call_user_func_array(array(&$this, $urlname), $params);
}elseif($urlname == "index") {
// If this is the index, redirect to the most recent startup
redirect("s/".$this->Startup_model->getMostRecent(), 'refresh');
} else {
// If they didn't go to the index, find the startup they were after
$id = $this->Startup_model->matchName($urlname);
// Check to see if the name they entered was a real startup, if not redirect to missing page
if($id == null) {
$data['urlname'] = $urlname;
$this->load->view('header/header');
$this->load->view('content/missing', $data);
$this->load->view('footer/footer');
} else {
// They got the name right! Load the page...
$data['values'] = $this->Startup_model->buildStartup($id);
// If there was no next startup avaiable, pass that info through
$next = $this->Startup_model->findNext($id);
if($next == null) {
$next = '343z61v';
}
// If there was no previous startup avaiable, pass that info through
$previous = $this->Startup_model->findPrevious($id);
if($previous == null) {
$previous = '343z61v';
}
$data['next'] = $next;
$data['previous'] = $previous;
$this->load->view('header/header');
$this->load->view('content/startup', $data);
$this->load->view('footer/footer');
}
}
}
Note:
Function index() should not exist
So you're asking how to selectively not remap certain urls? If so, add this to your if statement before the else:
else if (in_array($urlname, array('admin', 'contact', 'etc')))
{
$this->$urlname;
}