I got error in my Laravel controller that says syntax error, unexpected token "}", i have checked every line but couldn't identified the error reason.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Dompdf\Dompdf;
class WordController extends Controller
{
public function importForm()
{
return view('import');
}
public function importWord(Request $request)
{
$file_path = $request->file('word_file')->getRealPath();
try {
$word = new COM("Word.Application") or die("Unable to instantiate Word");
$word->Visible = 0;
$word->Documents->Open($file_path);
$content = $word->ActiveDocument->Content->Text;
$word->Quit();
$word = null;
unset($word);
} catch (Exception $e) {
return redirect()->back()->with('error', 'An error occurred while importing the Word document');
}
$dompdf = new Dompdf();
$dompdf->loadHtml($content);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
return $dompdf->stream();
}
}
Related
please can someone advice on making this code compatible, possibly it got broken during PHP 7.4 upgrade... it's a solution developed 5 years ago and now it got broken.
I'm not developer...so apologies for that possibly trivial request.
PHP Fatal error: Uncaught Error: Call to undefined method Delete::delete()
$userRightModel = new UserRightDb();
$userRightSelectModel = $userRightModel->getSelectModel();
$userRightSelectModel->setWhereEqual(UserRightDb::COLUMN_USER_ID, $id);
$userRightList = $userRightSelectModel->get();
foreach($userRightList as $userRightObject) {
$userRightModel = new UserRightDb();
$userRightDeleteModel = $userRightModel->getDeleteModel();
$userRightDeleteModel->setValue($userRightObject);
$userRightDeleteModel->delete(); <--- here it's broken
}
Possibly delete() is called from Delete.php which is included into DB.php library...
<?php
include_once 'MySql.php';
class Delete extends MySql {
protected $_table = null;
protected $_columns = array();
protected $_values = array();
protected $_object_name = null;
public function __construct() {
foreach($this->_values as $object) {
$queryString = $this->toString($object);
$mysql_data = $this->execute($queryString);
}
}
public function setObjectName($objectName) {
$this->_object_name = $objectName;
}
public function setTable($tableName) {
$this->_table = $tableName;
}
public function setColumns($columns) {
$this->_columns = $columns;
}
public function setValue($value) {
$this->_values = array();
$this->_values[] = $value;
}
protected function toString($object) {
$result = 'DELETE FROM {table} WHERE {where}';
$result = str_replace('{table}', '`' . $this->_table . '`', $result);
$where = Db::COLUMN_ID . MySQL::EQUAL . "'" . $object->getId() ."'";
$result = str_replace('{where}', $where, $result);
return $result;
}
}
?>
Thank you.
Code Below, basic example, but I want to return errors (see commented out if statement after the import ). How would I pass variables from the 'import' class back to the controller?
Controller:
public function resultsImport(Request $request)
{
//validate the xls file
$this->validate($request, array('student_results_import_file' => 'required'));
if($request->hasFile('student_results_import_file')){
$extension = File::extension($request->student_results_import_file->getClientOriginalName());
if ($extension == "xlsx" || $extension == "xls" || $extension == "csv") {
Excel::import(new StudentResultsImport, $request->file('student_results_import_file'));
// if $ignore_count>0 --> do stuff
return redirect('/baadmin/students')->with('flash_message', ['success','Results Imported Successfully','Student file "'. $request->student_results_import_file->getClientOriginalName() .'" imported successfully!']);
} else {
return redirect('/baadmin/students')->with('flash_message', ['error','Results Import Failed','Student file "'. $request->student_results_import_file->getClientOriginalName() .'" import failed. File is a '. $extension .' file. Please upload a valid xls/csv file.']);
}
}
}
Import
public function collection(Collection $rows)
{
set_time_limit(300);
$ignore_count = 0;
foreach ($rows as $row) {
if ($row[8] != '') {
//import
}
else {
$ignore_count++;
//$ignore_count is just a simple example, ultimately would probably have an array of the various errors detected on the various rows
}
}
}
Managed to find the appropriate answer in the documentation, referring to 'Getters':
https://docs.laravel-excel.com/3.1/architecture/objects.html#getters
eg:
namespace App\Imports;
use App\User;
use Maatwebsite\Excel\Concerns\ToModel;
class UsersImport implements ToModel
{
private $rows = 0;
public function model(array $row)
{
++$this->rows;
return new User([
'name' => $row[0],
]);
}
public function getRowCount(): int
{
return $this->rows;
}
}
After doing the import, we can request the state with the getter.
$import = new UsersImport;
Excel::import($import, 'users.xlsx');
dd('Row count: ' . $import->getRowCount());
I am able to parse HTMl that uses blade template variables through the following code:
$generated = Blade::compileString($string);
ob_start();
try
{
eval($generated);
}
catch (\Exception $e)
{
ob_get_clean(); throw $e;
}
$content = ob_get_clean();
return $content;
And it works fine as long as i don't use blade variables within. Which on being parsed give me undefined variable error. How can i make sure that blade variables are available in my custom parsing method?
This works for me with the latest version of Laravel 5.7. Notice how I include the __env var so that functions like #include, #foreach, etc can work.
public static function renderBlade($string, $data = null)
{
if (!$data) {
$data = [];
}
$data['__env'] = app(\Illuminate\View\Factory::class);
$php = Blade::compileString($string);
$obLevel = ob_get_level();
ob_start();
extract($data, EXTR_SKIP);
try {
eval('?' . '>' . $php);
} catch (Exception $e) {
while (ob_get_level() > $obLevel) {
ob_end_clean();
}
throw $e;
} catch (Throwable $e) {
while (ob_get_level() > $obLevel) {
ob_end_clean();
}
throw new FatalThrowableError($e);
}
return ob_get_clean();
}
Turns out I was not passing the arguments array to the method that parses the Blade structure. My assumption was that the Mail::send method takes care of making variables available which it takes in as a second parameter. I also had to extract($args, EXTR_SKIP).
$generated = Blade::compileString($string);
ob_start(); extract($args, EXTR_SKIP)
try
{
eval($generated);
}
catch (\Exception $e)
{
ob_get_clean(); throw $e;
}
$content = ob_get_clean();
return $content;
I'm using CodeIgniter with NuSOAP library for webservices and this is the error I get when accessing the Client controller:
wsdl error: XML error parsing WSDL from http://localhost/turismoadmin/index.php/Webservice/index/wsdl on line 77: Attribute without value
This is the server controller:
class Webservice extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->library('soap_lib');
$server = new nusoap_server;
$server->configureWSDL('Agencia Turistica', 'urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->register('addcontact',
array('nombre' => 'xsd:string', 'apellido' => 'xsd:string' , 'ciudad' => 'xsd:string'),
array('return' => 'xsd:string'));
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA: '';
$server->service($HTTP_RAW_POST_DATA);
}
function index()
{
if($this->uri->rsegment(3)=="wsdl"){
$_SERVER['QUERY_STRING']="wsdl";
}else{
$_SERVER['QUERY_STRING']="";
}
function addcontact($nombre, $apellido, $ciudad){
$this->modelo_turismo->addcontact($nombre, $apellido, $ciudad);
$resultado = $this->modelo_turismo->selectmax_contacto();
return (json_encode($resultado->fetch_all()));
}
}
}
and this is the Client controller:
class Client extends CI_controller {
function __construct() {
parent::__construct();
}
function index() {
$this->load->library('soap_lib');
$this->nusoap_client = new nusoap_client(site_url('Webservice/index/wsdl'), true);
$err = $this->nusoap_client->getError();
if ($err){
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$result1 = $this->nusoap_client->call('addcontact', array("marcos","de lafuente","hermosillo"));
echo($result1);
// Check for a fault
if ($this->nusoap_client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result1);
echo '</pre>';
} else {
// Check for errors
$err = $this->nusoap_client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result1);
echo '</pre>';
}
}
}
}
I'm trying to do it based
ON THIS TOPIC (Thanks nana.chorage)
I also added this entry to my config/routes.php
$route['Webservice/wsdl']="Webservice/index/wsdl";
And for not to pass unnoticed, I can see my service when I enter this URL:
http://localhost/turismoadmin/index.php/Webservice/wsdl
I really dont know what I'm doing wrong, I have searched a lot around and I can't get rid of it!
Then nusoap client URL should be like this
$this->nusoap_client = new nusoap_client(site_url('Webservice/index?wsdl'), 'wsdl');
I am trying insert data in my table but allways get this error
Fatal error: Call to undefined method UltimoValue_Warranty_Model_Mysql4_Warranty_Collection::setData() in
/var/www/magento.dev/app/code/community/UltimoValue/Warranty/controllers/IndexController.php
on line 17
here is the saving code in IndexController
public function saveAction()
{
$warrantiesCollection = Mage::getModel('warranty/warranty')->getCollection();
$post = $this->getRequest()->getPost();
if(isset($post['order_number']) && isset($post['save'])) {
try {
$warrantiesCollection->setData('id', null);
$warrantiesCollection->setData('first_name', $post['first_name']);
$warrantiesCollection->setData('last_name', $post['last_name']);
$warrantiesCollection->setData('order_number', $post['order_number']);
$warrantiesCollection->setData('tablet_serial_number', $post['tablet_serial_number']);
$warrantiesCollection->setData('date_purchased', $post['date_purchased']);
$warrantiesCollection->save();
} catch(Exception $e) {
echo $e->getMessage(), "\n";
}
header("Location: " . $_SERVER['HTTP_ORIGIN'] . "/index.php/warranty/index/thankyou/");
exit();
}
}
when i am using getData - all fine...
What i am doing wrong ?
instead
$warrantiesCollection = Mage::getModel('warranty/warranty')->getCollection();
i have to write
$warrantiesCollection = Mage::getModel('warranty/warranty');
thanks to all