I need help. when i open my index it shows that the nama_unit_kerja variable is not defined..
But i've put them in the SiteController. How can i fix this.
This is my SiteController code :
public function actionIndex()
{
//$this->layout = "//layouts/adr/main";
/* $browser = Yii::app()->browser->isMobile();
echo ($browser?'mobile':'not mobile'); exit; */
#session_start();
Yii::app()->user->returnUrl = array('site/index');
$lang = 'en';
if(isset($_SESSION['lang'])) $lang = $_SESSION['lang'];
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->layout='//layouts/erp/index';
$modelUnitKerja=new UnitKerja('searchKapTarReal');
$modelUnitKerja->unsetAttributes(); // clear any default values
$modelJenisKegiatan=new JenisKegiatan('searchKapTarReal');
$modelJenisKegiatan->unsetAttributes(); // clear any default values
//var_dump($_POST);exit;
if ((isset($_POST['unitKerja'])) or (isset($_POST['year']))){
if(empty($_POST['unitKerja'])){
$unitKerja = 0;
} else {
$unitKerja = $_POST['unitKerja'];
$nama_unit_kerja = UnitKerja::model()->findByAttributes(array("id"=>$_POST['unitKerja']))->nama_unit_kerja;
}
$year = $_POST['year'];
$year_nm = Year::model()->findByAttributes(array("id"=>$_POST['year']))->year;
}else{
$unitKerja = 0;
$year = Year::model()->findByAttributes(array("year"=>date('Y')))->id;
$year_nm = date('Y');
}
$this->render('index',array(
'mJenisKegiatan'=>$modelJenisKegiatan,
'mUnitKerja'=>$modelUnitKerja,
'unitKerja'=>$unitKerja,
'nama_unit_kerja'=>$nama_unit_kerja,
'year'=>$year,
'year_nm'=>$year_nm,
));
}
$nama_unit_kerja = UnitKerja::model()->findByAttributes(array("id"=>$_POST['unitKerja']))->nama_unit_kerja;
hopefully you are getting this error on this line because you are trying to access the property of yii base.
you can use it like
$nama_unit_kerja = UnitKerja::model()->findByAttributes(array("id"=>$_POST['unitKerja']));
$nama_unit_kerja=$nama_unit_kerja->$nama_unit_kerja;
Related
When I try to get all titles of spreadsheets from Google drive, I got this message The string could not be parsed as XML:
ERROR -> SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in C:\....
ERROR-> SimpleXMLElement::__construct(): { in C:\....
ERROR-> SimpleXMLElement::__construct(): ^ in C:\...
I try to connect on Gooogle drive, which I success, but I need to get the names of spreadsheets on Google drive, I previously use API v3 now I need to use V4.
this is code for call method getSpreadsheets();
$serviceRequest = new DefaultServiceRequest($token->access_token, $token->token_type);
ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
This is the code of method getSpreadsheets:
public function getSpreadsheets()
{
return new SpreadsheetFeed(
ServiceRequestFactory::getInstance()->get('v4/spreadsheets/1u7WYzJOYMX7uH3AIM70yVLOaHBy8p_uifuJe_Saa2T4?fields=sheets.properties.title')
);
}
And this is SpreadsheetFeed class, where is error causes:
namespace Google\Spreadsheet;
use ArrayIterator;
use SimpleXMLElement;
/**
* Spreadsheet feed.
*
* #package Google
* #subpackage Spreadsheet
* #author Asim Liaquat <asimlqt22#gmail.com>
*/
class SpreadsheetFeed extends ArrayIterator
{
/**
* The spreadsheet feed xml object
*
* #var \SimpleXMLElement
*/
protected $xml;
/**
* Initializes the the spreadsheet feed object
*
* #param string $xml the raw xml string of a spreadsheet feed
*/
public function __construct($xml)
{
$this->xml = new SimpleXMLElement($xml);
$spreadsheets = array();
foreach ($this->xml->entry as $entry) {
$spreadsheets[] = new Spreadsheet($entry);
}
parent::__construct($spreadsheets);
}
/**
* Gets a spreadhseet from the feed by its title. i.e. the name of
* the spreadsheet in google drive. This method will return only the
* first spreadsheet found with the specified title.
*
* #param string $title
*
* #return \Google\Spreadsheet\Spreadsheet|null
*/
public function getByTitle($title)
{
foreach($this->xml->entry as $entry) {
if($entry->title->__toString() == $title) {
return new Spreadsheet($entry);
}
}
return null;
}
}
I try to find a solution how to pass this error!
Any Help, how to solve this error?
Thanks!
This is solution for my app, migrate from v3 to v4 spreadsheets API:
$this->service_drive = new Google_Service_Drive($this->client);
$optParams = array('q'=> 'mimeType="application/vnd.google-apps.spreadsheet"');
$this->files = $this->service_drive->files->listFiles($optParams);
}
// $this->service_drive = new Google_Service_Drive($this->client);
//$optParams = array('q'=> 'mimeType="application/vnd.google-apps.spreadsheet"');
//$this->files = $this->service_drive->files->listFiles($optParams);
//$gdata_spreadsheets=$this->files;//my test
if($this->files !==null){
if (count($this->files->getFiles()) == 0) {
$gdata_spreadsheets=array("No Spreadsheets");
} else {
foreach ($this->files->getFiles() as $file) {
$gdata_spreadsheets[$file->getId()]=$file->getName();
}
}
}
//trenuto ispod code rjesavam
if($gdata->spreadsheet_id != '' && isset( $gdata_spreadsheets[$gdata->spreadsheet_id] ) && $this->files !== null){
$this->service = new Google_Service_Sheets($this->client);
$this->response = $this->service->spreadsheets->get($gdata->spreadsheet_id);
$this->sheets=$this->response->getSheets();
// $spreadsheet = $this->service_drive($gdata_spreadsheets[$gdata->spreadsheet_id]);
// $worksheetFeed = $spreadsheet->getWorksheets();
foreach ( $this->sheets as $sheet ){
$gdata_worksheets[$sheet->properties->sheetId]= $sheet->properties->title;
//$gdata_worksheets[]=$this->sheets;
}
//$gdata_worksheets[]=$gdata->worksheet_id;
if($gdata->worksheet_id != '' && isset( $gdata_worksheets[$gdata->worksheet_id] )){
$range = 'List 2!A1:Z';
$worksheet = $this->service->spreadsheets_values->get($gdata->spreadsheet_id, $range);
$cellFeed = $worksheet->getValues();
foreach( $cellFeed As $row) {
//$row = $cellEntry->getRow();
//$col = $cellEntry;
// $gdata_worksheets=$this->service;
if( $row > 1 ){
$gdata_columns=$row;
break;
}
}
}
}
} catch(Exception $e){
$error = $e->getMessage();
}
This is one part of my code, where is described how to migrate from v3 to v4 spreadsheets API.
I am using TYPO3 10.4.15 and try to write a TcaProcFunc for my own extension.
namespace HGA\Album\UserFunc;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use HGA\Album\Domain\Repository\AlbumRepository;
use HGA\Album\Domain\Model\Album;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
class TcaProcFunc
{
/**
* #param array $config
*
*/
public function getLink(&$config)
{
$ret = [];
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$albumRepository= $objectManager->get(AlbumRepository::class);
$albums = $albumRepository->findAll();
foreach ($albums as $album){
$ret[] = ["Test1","Test1"];
}
$i = count($albums);
error_log("Album: " . $i, 0 );
$ret[] = ["Test", "Test"];
$config['items'] = $ret;
// error_log("UserFunc: " . var_export($config, true), 0);
}
}
The problem is, that findall() does not provide any result. $albumsis empty, but there is one record inside the database.
HGA is my vendor name and Album the extension name. The TcaProcFunc is in generell is working, but I don't have any access to the extension database.
Can anybody tell me, what is wrong with my code or how I what I can do to findthe problem?
Thank you in advance.
Finally I did it with ConnectionPool
namespace HGA\Album\UserFunc;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Core\Database\ConnectionPool;
class TcaProcFunc
{
/**
* #param array $config
*
*/
public function getLink(&$config)
{
$ret = [];
$albums = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('tx_album_domain_model_album')
->select(
['uid', 'album_artist', 'album'],
'tx_album_domain_model_album',
[]
)->fetchAll();
foreach ($albums as $album){
$ret[] = [$album['album_artist'] . ": " . $album['album'], $album['uid']];
}
$config['items'] = $ret;
}
}
public function actionFind()
{
$response = Yii::$app->response;
\Yii::$app->response->format = yii\web\Response::FORMAT_RAW;
\Yii::$app->response->headers->add('content-type', 'image/jpg');
$img_url = file_get_contents('images/ab.jpg');
Yii::$app->response->data($img_url);
return \Yii::$app->response;
}
why this code has error??
error is :
cannot be displayed because it contains errors
data is property, not function http://www.yiiframework.com/doc-2.0/yii-web-response.html#$data-detail
public function actionFind()
{
$response = \Yii::$app->response;
$response->format = yii\web\Response::FORMAT_RAW;
$response->headers->add('content-type', 'image/jpg');
$img_data = file_get_contents('images/ab.jpg');
$response->data = $img_data;
return $response;
}
I'm trying to save the data from a form. The yii framework form attributes is not being saved in the database.
Here is my code for the controller:
class ProfileController extends Controller {
public function actionSave() {
if (isset($_POST['Patients'])) {
$patients = new Patients;
$patients->name = $_POST['Patients']['name'];
$patients->mobile = $_POST['Patients']['mobile'];
$patients->email = $_POST['Patients']['email'];
$patients->password = $_POST['Patients']['password'];
$patients->dob = $_POST['Patients']['dob'];
$patients->weight = $_POST['Patients']['weight'];
$patients->height = $_POST['Patients']['height'];
$patients->activation_date = '0000-00-00';
$patients->credit = 0;
$patients->archive = 0;
$patients->balance = 0;
$patients->first_login = 0;
$patients->guide_status = 0;
$patients->passcode = '';
}
//echo $patients->save_personal_data();
$valid = $patients->validate();
if ($valid) {
$patients->save();
} else {
var_dump($patients->getErrors());
}
if ($patients->save()) {
echo 'saved';
} else {
var_dump($patients->getErrors());
}
}
It isn't saving in the database. What is wrong with the above code?
It won't save in the DB. Typically the issue is related to the validation rules.
Just for debugging, try using save(false)
//$valid = $patients->validate();
$patients->save(false);
If the model is saved, then check selectively for rules applied to the model.
sendmail.php
This is just sample of attachment.in which i m confused...
class sendmail()
public $ATTACHMENT = array();
public function MailSend()
{
$message = new YiiMailMessage;
$message->subject = $this->SUBJECT;
$message->from = $this->FROM;
$message->setBody($this->EMAILBODY, 'text/html','utf-8');
$message->addTo($this->EMAILTO);
if (count($this->ATTACHMENT) > 0)
{
foreach ($this->ATTACHMENT as $Attachement_Array)
{
if (isset($Attachement_Array['filepath']) && $Attachement_Array['filename'] && $Attachement_Array['mimetype'] && file_exists($Attachement_Array['filepath']))
{
$message->attach(Swift_Attachment::fromPath($Attachement_Array['filepath']), $Attachement_Array['filename'], $Attachement_Array['mimetype']);
}
}
}
}
}
mycontroller.php
here in
$SendMail->ATTACHMENT = array("what to pass here");
please explain me
i want multiple dimensional array of filepath,mimetype,filename
/** SEND EMAIL USING COMMON EMAIL FUNCTIONALITY */
$SendMail = new SendMail;
$SendMail->DRAFT_ID = $id;
$SendMail->SUBJECT = $modelEmail->subject;
$SendMail->FROM = $modelEmail->email_from;
$SendMail->CMPAIGN_ID = 1;
$SendMail->TAG_ARRAY = array("[FIRSTNAME]"=>$profiledata->name,"[EMAIL]"=>$profiledata->email,"[CONTACT_NO]"=>$profiledata->contact_no,"[ADDRESS]"=>$profiledata->address,"[WEBSITE]"=>$profiledata->website);
$SendMail->EMAILTO = $profiledata->name."<".$profiledata->email.">";
$SendMail->ATTACHMENT = array('filepath'=>Yii::app()->params['var_path']."stationary.html"); /// what to write here... i want multidimension array here
$SendMail->MailSend();
/** SEND EMAIL USING COMMON EMAIL FUNCTIONALITY */
my answer is
$attach1 = array();
$attach2 = array();
$attach1 = array('filepath'=>Yii::app()->params['var_path']."stationary.html",
'filename'=>"stationary.html",
'mimetype'=>"application/html",);
$attach2 = array('filepath'=>Yii::app()->params['var_path']."pregmatch1_old.php",
'filename'=>"pregmatch1_old.php",
'mimetype'=>"application/php",);
$SendMail->ATTACHMENT = array($attach1,$attach2);